private void btnSignUp_Click(object sender, EventArgs e) { using (var ctx = new UsersContext()) { var login = MetaBackEnd.getCorrectLogin(tbLogin.Text); var rawpass = MetaBackEnd.getCorrectLogin(tbPass.Text); var birthDate = dtpBirthDate.Value; var signUpDate = DateTime.Now; var idSpecial = ctx.specials.SingleOrDefault(spec => tbSpecial.Text == spec.special_code).id; var bsalt = MetaBackEnd.GenerateSalt(); var bpass = MetaBackEnd.CalcHash(rawpass, bsalt); var newUser = new awp_users { gender = genderName, login_ = login, password = bpass, birth_date = birthDate, signup_date = signUpDate, salt = bsalt, id_special = idSpecial }; ctx.awp_users.Add(newUser); ctx.SaveChanges(); } }
private void btnLogIn_Click(object sender, EventArgs e) { using (var ctx = new UsersContext()) { var user = ctx.awp_users.SingleOrDefault(us => us.login_ == tbLogin.Text); if (user != default) { var bsaltCurUser = user.salt; var rawPass = tbPass.Text; var bpassCurUser = MetaBackEnd.CalcHash(MetaBackEnd.getCorrectPass(rawPass), bsaltCurUser); if (user.password.SequenceEqual(bpassCurUser)) { var roleId = ctx.specials.Find(user.id_special).id_role; var roleIndex = ctx.roles.Find(roleId).id; var formAwp = new FormAWP(roleIndex); Hide(); if (formAwp.ShowDialog() == DialogResult.Cancel) { MessageBox.Show("Good bye"); } tbLogin.Text = tbPass.Text = ""; Show(); } else { MessageBox.Show("Your password is wrong"); } } else { MessageBox.Show("Your login is wrong"); } } }
private void CheckPassword(DataGridViewCell cell) { var clearPass = MetaBackEnd.getCorrectPass(cell.Value as string); var zxcvbn = Zxcvbn.Zxcvbn.MatchPassword(clearPass); if (!(zxcvbn.Score > 2)) { cell.ErrorText = "Password too easy"; isPassValid = false; } else { if (!(clearPass.Length <= 20)) { cell.ErrorText = "Password can't contain over 20 symbols"; isPassValid = false; } else { cell.ErrorText = ""; isPassValid = true; var rawpass = MetaBackEnd.getCorrectPass(cell.Value as string); var bsalt = MetaBackEnd.GenerateSalt(); var bpass = MetaBackEnd.CalcHash(rawpass, bsalt); cell.Value = bpass; cell.Tag = bsalt; } } SyncBtnSignUpState(); }