private void userLoginButton_Click(object sender, EventArgs e)
        {
            string salt = "";

            using (var context = new Entities())
            {
                var getEmailAddressBusinessID = new Repository.PersonRepository.EmailAddress(context);
                var getSalt = new Repository.PersonRepository.Password(context);
                salt = getSalt.GetSaltByBussinessEntityID(getEmailAddressBusinessID
                                                          .GetEmailAddressBusinessEntityIDByEmail(
                                                              this.userEmailAddress.Text));
            }

            var userValidation = new UserLogin();

            var hasEmail   = userValidation.isUserName(this.userEmailAddress.Text);
            var isPassword = userValidation.IsPasswordCorrect(this.userPassword.Text, this.userEmailAddress.Text);

            if (hasEmail && isPassword)
            {
                this.Hide();
                var employeeForm = new NewEmployee(this);
                employeeForm.Show();
            }
            else
            {
                MessageBox.Show("Invalid User Email or Password.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #2
0
        public bool IsPasswordCorrect(string password, string emailaddress)
        {
            string salt            = "";
            string currentPassword = "";
            var    validation      = new CreatePassword();

            using (var context = new Entities())
            {
                var emailAddress   = new Repository.PersonRepository.EmailAddress(context);
                var storedPassword = new Repository.PersonRepository.Password(context);
                var getSalt        = new Repository.PersonRepository.Password(context);
                salt = getSalt.GetSaltByBussinessEntityID(emailAddress
                                                          .GetEmailAddressBusinessEntityIDByEmail(emailaddress));
                currentPassword = storedPassword
                                  .GetPasswordByBusinessEntityID(emailAddress
                                                                 .GetEmailAddressBusinessEntityIDByEmail(emailaddress));
            }

            var hashPassword      = validation.CreateHashPassword(password);
            var hashSaltyPassword = validation.HashPasswordAndSalt($"{hashPassword}{salt}");

            if (currentPassword != null && currentPassword.Equals(hashSaltyPassword))
            {
                return(true);
            }
            return(false);
        }