private bool VerifyPassword(string password, UserData userDetailsToVerify)
        {
            string hash;
            string salt;

            _passwordHashAlgorithm.Hash(password, out hash, out salt);
            return(_passwordHashAlgorithm.Verify(password, userDetailsToVerify.Hash, userDetailsToVerify.Salt));
        }
        public void Handle(UserManagementMessage.ResetPassword message)
        {
            if (!DemandAdmin(message))
            {
                return;
            }
            string hash;
            string salt;

            _passwordHashAlgorithm.Hash(message.NewPassword, out hash, out salt);
            ReadUpdateWriteReply(message, data => data.SetPassword(hash, salt), resetPasswordCache: true);
        }
Example #3
0
        private void logButton_Click(object sender, EventArgs e)
        {
            var unitOfWork = new UnitOfWork();

            var username = this.userName.Text;
            var password = PasswordHashAlgorithm.Hash(this.passwordBox.Text);

            var currentUser = unitOfWork.Users.First(user => user.UserName == username);

            if (currentUser == null || currentUser.PasswordHash != password)
            {
                this.wrongLabel.Visible = true;
                this.userName.Text      = string.Empty;
                this.passwordBox.Text   = string.Empty;
            }
            else
            {
                currentUser.IsLogged = true;
                unitOfWork.Commit();

                this.Hide();
                var menu = new Frm_Menu();
                menu.Closed += (s, args) => this.Close();
                menu.Show();
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            this.HideAll();

            var unitOfWork = new UnitOfWork();

            var userName           = this.userNameRegister.Text;
            var password           = this.passwordRegister.Text;
            var confirmPassword    = this.confirmPasswordRegister.Text;
            var email              = this.emailRegister.Text;
            var validationUsername = UsernameRegisterValidation.IsValid(userName);
            var validationPassword = PasswordRegisterValidation.IsValid(password);
            var validationEmail    = EmailRegisterValidation.IsValid(email);

            if (validationUsername != UsernameRegisterValidation.UsernameType.Success)
            {
                if (validationUsername == UsernameRegisterValidation.UsernameType.Empty)
                {
                    this.usernameEmpty.Visible = true;
                }
                else if (validationUsername == UsernameRegisterValidation.UsernameType.Lenght)
                {
                    this.usernameLenght.Visible = true;
                }
                else
                {
                    this.usernameInvalid.Visible = true;
                }
            }
            else if (unitOfWork.Users.Any(user => user.UserName == userName.ToLower()))
            {
                this.usernameExists.Visible = true;
            }
            else if (validationPassword != PasswordRegisterValidation.PasswordType.Success)
            {
                if (validationPassword == PasswordRegisterValidation.PasswordType.Empty)
                {
                    this.passwordEmpty.Visible = true;
                }
                else if (validationPassword == PasswordRegisterValidation.PasswordType.Lenght)
                {
                    this.passwordLenght.Visible = true;
                }
                else
                {
                    this.passwordInvalid.Visible = true;
                }

                this.passwordRegister.Text        = string.Empty;
                this.confirmPasswordRegister.Text = string.Empty;
            }
            else if (password != confirmPassword)
            {
                this.confirmPasswordInvalid.Visible = true;

                this.confirmPasswordRegister.Text = string.Empty;
            }
            else if (validationEmail != EmailRegisterValidation.EmailValidationMsg.Success)
            {
                if (validationEmail == EmailRegisterValidation.EmailValidationMsg.Empty)
                {
                    this.emailEmpty.Visible = true;
                }
                else
                {
                    this.emailInvalid.Visible = true;
                }

                this.emailRegister.Text = string.Empty;
            }
            else if (unitOfWork.Users.Any(user => user.Email == email.ToLower()))
            {
                this.emailExists.Visible = true;
            }
            else
            {
                User user = new User()
                {
                    UserName     = userName.ToLower(),
                    PasswordHash = PasswordHashAlgorithm.Hash(password),
                    Email        = email
                };

                unitOfWork.Users.Add(user);

                unitOfWork.Commit();

                MessageBox.Show("SUCCESSFUL REGISTRATION !!!");

                this.Hide();
                LoginForm login = new LoginForm();
                login.Closed += (s, args) => this.Close();
                login.Show();
            }
        }