示例#1
0
文件: FormAuth.cs 项目: Wykh/ARM
 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");
         }
     }
 }
示例#2
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();
            }
        }
示例#3
0
        private void tbPass_TextChanged(object sender, EventArgs e)
        {
            var clearPass = MetaBackEnd.getCorrectPass(tbPass.Text);
            var zxcvbn    = Zxcvbn.Zxcvbn.MatchPassword(clearPass);

            if (!(zxcvbn.Score > 2))
            {
                errorSign.SetError(tbPass, "Password too easy");
                isPassValid = false;
            }
            else
            {
                if (!(clearPass.Length <= 20))
                {
                    errorSign.SetError(tbPass, "Password can't contain over 20 symbols");
                    isPassValid = false;
                }
                else
                {
                    errorSign.SetError(tbPass, "");
                    isPassValid = true;
                }
            }
            SyncBtnSignUpState();
        }
示例#4
0
文件: FormUsers.cs 项目: Wykh/ARM
 private void CheckLogin(DataGridViewCell cell)
 {
     //Here is login cheking            i
     if (!loginRegex.IsMatch(MetaBackEnd.getCorrectLogin(cell.Value as string)))
     {
         cell.ErrorText = "Login должен состоять из 6 to 50 letters of 'А-Яа-я0-9A-Za-z' and space";
         isLoginValid   = false;
     }
     else
     {
         using (var ctx = new UsersContext())
         {
             var user = ctx.awp_users.SingleOrDefault(us => us.login_.ToLower() == ((string)cell.Value).ToLower());
             if (user != default)
             {
                 cell.ErrorText = "Login is already used";
                 isLoginValid   = false;
             }
             else
             {
                 cell.ErrorText = "";
                 isLoginValid   = true;
             }
         }
     }
     SyncBtnSignUpState();
 }
示例#5
0
文件: FormUsers.cs 项目: Wykh/ARM
        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();
        }
示例#6
0
 private void tbLogin_TextChanged(object sender, EventArgs e)
 {
     if (!loginRegex.IsMatch(MetaBackEnd.getCorrectLogin(tbLogin.Text)))
     {
         errorSign.SetError(tbLogin, "Login должен состоять из 6 to 50 letters of 'А-Яа-я0-9A-Za-z' and space");
         isLoginValid = false;
         return;
     }
     using (var ctx = new UsersContext())
     {
         var user = ctx.awp_users.SingleOrDefault(us => us.login_.ToLower() == tbLogin.Text.ToLower());
         if (user != default)
         {
             errorSign.SetError(tbLogin, "Login is already used");
             isLoginValid = false;
         }
         else
         {
             errorSign.SetError(tbLogin, "");
             isLoginValid = true;
         }
     }
 }
示例#7
0
文件: FormAuth.cs 项目: Wykh/ARM
 public FormAuth()
 {
     InitializeComponent();
     MetaBackEnd.WarmupDbConnectionToUsers();
 }
示例#8
0
 public FormReg()
 {
     InitializeComponent();
     MetaBackEnd.WarmupDbConnectionToUsers();
     btnSignUp.Enabled = false;
 }