Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class Start : Form
- {
- private HostelEntities aux = new HostelEntities();
- private MD5 crypto;
- public Start()
- {
- InitializeComponent();
- tmp.Visible = false;
- crypto = MD5.Create();
- }
- public void ClearTextBoxEdit()
- {
- textBox_login.Text = "";
- textBox_pass.Text = "";
- }
- private void tmp_Click(object sender, EventArgs e)
- {
- StartHostel start = new StartHostel();
- start.Show();
- this.Hide();
- }
- private void enter_Click(object sender, EventArgs e)
- {
- if (textBox_login.Text != string.Empty && textBox_pass.Text != string.Empty && textBox_login.Text.Length > 5 && textBox_pass.Text.Length > 5)
- {
- string login = GetMd5Hash(crypto, textBox_login.Text);
- string password = GetMd5Hash(crypto, textBox_pass.Text);
- List<Auth> listAuth = aux.Auths.ToList();
- var level = from Auth in listAuth
- where Auth.Login == login && Auth.Pass == password
- select new { level = Auth.Level }.level;
- if (level.Any())
- {
- ClearTextBoxEdit();
- StartHostel user = new StartHostel();
- user.Show();
- this.Hide();
- }
- else
- {
- MessageBox.Show("Ошибка! Пользователь не найден.");
- ClearTextBoxEdit();
- }
- }
- else MessageBox.Show("Ошибка! Заполнены не все поля либо введенные значения нарушают допустимые ограничения(Логин и Пароль не менее 6 символов каждый)!");
- }
- static string GetMd5Hash(MD5 md5Hash, string input)
- {
- byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
- StringBuilder sBuilder = new StringBuilder();
- for (int i = 0; i < data.Length; i++)
- {
- sBuilder.Append(data[i].ToString("x2"));
- }
- return sBuilder.ToString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement