Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.72 KB | None | 0 0
  1. public partial class Start : Form
  2. {
  3. private HostelEntities aux = new HostelEntities();
  4. private MD5 crypto;
  5. public Start()
  6. {
  7. InitializeComponent();
  8. tmp.Visible = false;
  9. crypto = MD5.Create();
  10. }
  11.  
  12. public void ClearTextBoxEdit()
  13. {
  14. textBox_login.Text = "";
  15. textBox_pass.Text = "";
  16. }
  17.  
  18. private void tmp_Click(object sender, EventArgs e)
  19. {
  20. StartHostel start = new StartHostel();
  21. start.Show();
  22. this.Hide();
  23. }
  24.  
  25. private void enter_Click(object sender, EventArgs e)
  26. {
  27. if (textBox_login.Text != string.Empty && textBox_pass.Text != string.Empty && textBox_login.Text.Length > 5 && textBox_pass.Text.Length > 5)
  28. {
  29. string login = GetMd5Hash(crypto, textBox_login.Text);
  30. string password = GetMd5Hash(crypto, textBox_pass.Text);
  31. List<Auth> listAuth = aux.Auths.ToList();
  32. var level = from Auth in listAuth
  33. where Auth.Login == login && Auth.Pass == password
  34. select new { level = Auth.Level }.level;
  35. if (level.Any())
  36. {
  37. ClearTextBoxEdit();
  38. StartHostel user = new StartHostel();
  39. user.Show();
  40. this.Hide();
  41. }
  42. else
  43. {
  44. MessageBox.Show("Ошибка! Пользователь не найден.");
  45. ClearTextBoxEdit();
  46. }
  47.  
  48. }
  49. else MessageBox.Show("Ошибка! Заполнены не все поля либо введенные значения нарушают допустимые ограничения(Логин и Пароль не менее 6 символов каждый)!");
  50. }
  51.  
  52. static string GetMd5Hash(MD5 md5Hash, string input)
  53. {
  54. byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
  55. StringBuilder sBuilder = new StringBuilder();
  56. for (int i = 0; i < data.Length; i++)
  57. {
  58. sBuilder.Append(data[i].ToString("x2"));
  59. }
  60. return sBuilder.ToString();
  61. }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement