FormAutorization.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace СУБД_Альфапол
  11. {
  12. public partial class FormAutorization : Form
  13. {
  14. public FormAutorization()
  15. {
  16. InitializeComponent();
  17. }
  18. public static string Captcha, id;
  19. void GetCaptcha()
  20. {
  21. Captcha = Guid.NewGuid().ToString();
  22. Captcha = Captcha.Substring(0, 4).ToUpper();
  23. LblC1.Text = Captcha[0].ToString();
  24. LblC2.Text = Captcha[1].ToString();
  25. LblC3.Text = Captcha[2].ToString();
  26. LblC4.Text = Captcha[3].ToString();
  27. TbxCaptcha.Clear();
  28. }
  29. private void Form1_Load(object sender, EventArgs e)
  30. {
  31. // TODO: This line of code loads data into the 'dbAlphapolAGDataSet.Manager' table. You can move, or remove it, as needed.
  32. this.managerTableAdapter.Fill(this.dbAlphapolAGDataSet.Manager);
  33. lblIdManager.Hide();
  34. }
  35. private void cbxShowPass_CheckedChanged(object sender, EventArgs e)
  36. {
  37. tbxPass.UseSystemPasswordChar = !cbxShowPass.Checked;
  38. }
  39. private void btnLogin_Click(object sender, EventArgs e)
  40. {
  41. BsUsers.Filter = $"Login = '{tbxLogin.Text}' and Password = '{tbxPass.Text}'";
  42. id = lblIdManager.Text;
  43. if (PanelInputCaptcha.Visible)
  44. {
  45. if (TbxCaptcha.Text != Captcha)
  46. {
  47. GetCaptcha();
  48. btnLogin.Enabled = false;
  49. timerForLogin.Start();
  50. MessageBox.Show("Символы капчи введены неверно!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information);
  51. return;
  52. }
  53. }
  54. if (BsUsers.Count == 0)
  55. {
  56. if (PanelInputCaptcha.Visible == false)
  57. {
  58. GetCaptcha();
  59. PanelInputCaptcha.Visible = true;
  60. }
  61. else
  62. {
  63. btnLogin.Enabled = false;
  64. timerForLogin.Start();
  65. }
  66. MessageBox.Show("Нет пользователя с указанным логином и паролем", "Внимание", MessageBoxButtons.OK,
  67. MessageBoxIcon.Information);
  68. return;
  69. }
  70. this.Hide();
  71. FormManager frmManager = new FormManager();
  72. frmManager.ShowDialog();
  73. this.Show();
  74. tbxLogin.Clear();
  75. tbxPass.Clear();
  76. tbxLogin.Focus();
  77. PanelInputCaptcha.Visible = false;
  78. }
  79. private void timerForLogin_Tick(object sender, EventArgs e)
  80. {
  81. timerForLogin.Stop();
  82. btnLogin.Enabled = true;
  83. }
  84. private void panel1_Paint(object sender, PaintEventArgs e)
  85. {
  86. }
  87. }
  88. }