public bool AddNewUser(object sender, EventArgs e, string login, string password, string passwordRepeat)
        {
            bool validationParametr = true;

            if (password == passwordRepeat)
            {
                string      salt         = RegistrationModel.CreateSalt(10);
                string      hashpassword = RegistrationModel.GenerateSHAHash256(password, salt);
                List <User> users        = Db.Users.ToList();
                User        user         = new User(login, hashpassword, salt);
                var         character    = users.Find(c => c.Login == login);
                if (character is null)
                {
                    Db.Add(user);
                    Db.SaveChanges();
                }
                else
                {
                    validationParametr = false;
                    string errorMessage = FormattableString.Invariant($"This login already exists");
                    MessageBox.Show(errorMessage);
                }
            }
            else
            {
                validationParametr = false;
                string errorMessage = FormattableString.Invariant($"Passwords do not match");
                MessageBox.Show(errorMessage);
            }
            return(validationParametr);
        }
Exemple #2
0
        public bool CheckUser(object sender, EventArgs e, string login, string password)
        {
            bool        authorizationCheck = false;
            List <User> users     = Db.Users.ToList();
            var         checkuser = users.Find(c => c.Login == login);

            if (checkuser is null)
            {
                return(false);
            }
            var checkpassword = RegistrationModel.GenerateSHAHash256(password, checkuser.Salt);

            if (checkpassword == checkuser.Password)
            {
                authorizationCheck = true;
            }
            return(authorizationCheck);
        }