Пример #1
0
        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();
            }
        }
Пример #2
0
        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();
        }