Esempio n. 1
0
        public void ValidateInput(string username, string password)
        {
            if (!RegistryData.GetUsernames().Contains(username))
            {
                throw new InvalidUsernameException(GlobalMessages.NonExistingUser);
            }

            string hashedPassword      = RegistryData.GetUserPassword(username);
            string currentPasswordHash = HashUtilities.HashPassword(password);

            if (hashedPassword != currentPasswordHash)
            {
                throw new InvalidPasswordLenghtException(GlobalMessages.IncorectPassword);
            }
        }
Esempio n. 2
0
        private void changeButton_Click(object sender, EventArgs e)
        {
            this.oldPassLabel.Visible = false;
            this.newPassLabel.Visible = false;

            string currentPassword     = this.oldPasswordTextBox.Text;
            string currentPasswordHash = HashUtilities.HashPassword(currentPassword);
            string hashedPassword      = RegistryData.GetUserPassword(this.User.Username);

            if (currentPasswordHash == hashedPassword)
            {
                try
                {
                    ValidateNewPassword(this.newPassTextBox.Text, this.confirmNewPassTextBox.Text);
                    string oldEncryptedData = RegistryData.GetUserData(this.User.Username);
                    string oldDecryptedData = CryptographicUtilities.Decrypt(oldEncryptedData, this.User.Key);
                    string newPassword      = HashUtilities.HashPassword(this.newPassTextBox.Text);
                    byte[] newKey           = HashUtilities.HashKey(this.newPassTextBox.Text);
                    string newData          = CryptographicUtilities.Encrypt(oldDecryptedData, newKey);
                    RegistryData.SetNewPassword(this.User.Username, newPassword);
                    RegistryData.SetUserData(this.User.Username, newData);
                    this.User.SetNewKey(newKey);

                    MetroMessageBox.Show(this.MainForm, string.Empty, GlobalMessages.PasswordChanged
                                         , MessageBoxButtons.OK, MessageBoxIcon.Information, 80);

                    this.Swipe(false);
                }
                catch (InvalidPasswordLenghtException ipe)
                {
                    this.newPassLabel.Text    = ipe.Message;
                    this.newPassLabel.Visible = true;
                }
                catch (PasswordMismatchException pme)
                {
                    this.newPassLabel.Text    = pme.Message;
                    this.newPassLabel.Visible = true;
                }
            }
            else
            {
                this.oldPassLabel.Text    = GlobalMessages.InvalidPassword;
                this.oldPassLabel.Visible = true;
            }
        }
Esempio n. 3
0
 private void deleteButton_Click(object sender, EventArgs e)
 {
     this.passwordLabel.Visible = false;
     if (!string.IsNullOrWhiteSpace(this.passwordTextBox.Text))
     {
         string hashedPass = HashUtilities.HashPassword(this.passwordTextBox.Text);
         if (hashedPass == RegistryData.GetUserPassword(this.User.Username))
         {
             RegistryData.DeleteAccout(this.User.Username);
             MetroMessageBox.Show(this.MainForm, string.Empty, GlobalMessages.AccountDeleted
                                  , MessageBoxButtons.OK, MessageBoxIcon.Information, 80);
             this.Swipe(false);
             this.userPanel.Logout();
         }
         else
         {
             this.passwordLabel.Visible = true;
         }
     }
 }