Ejemplo n.º 1
0
        private async void LoginUser(object obj)
        {
            try
            {
                PasswordBox pwBox    = obj as PasswordBox;
                var         password = pwBox.Password;
                pwBox.Clear();

                Model = await _apiClient.UserGetByEmailAsync(Email);

                var data = new PasswordComparer();
                if (data.ComparePassword(password, Model.Password))
                {
                    _mediator.Send(new UserLoginMessage {
                        Id = Model.Id
                    });
                }
                else
                {
                    MessageBox.Show(Resources.Texts.TextResources.WrongPassword_Message);
                }
            }
            catch (Exception)
            {
                MessageBox.Show(Resources.Texts.TextResources.NoUser_Message);
            }
            Model = null;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Compare a given salt and password to a previously hashed password.
 /// </summary>
 /// <param name="delegate">The current <see cref="PasswordComparer"/> implementation.</param>
 /// <param name="salt">A sequence of bytes representing the salt.</param>
 /// <param name="password">A string representing the clear password.</param>
 /// <param name="hashed">
 /// A sequence of bytes representing a previous result of hashing a salt and password.
 /// </param>
 /// <param name="encoding">
 /// An encoding to use to convert the given password to an array of bytes.
 /// </param>
 /// <returns>
 /// A value indicating whether or not the given salt and password equals the given hashed password.
 /// </returns>
 public static bool Compare(
     this PasswordComparer @delegate,
     byte[] salt,
     string password,
     byte[] hashed,
     Encoding encoding
     )
 {
     return(@delegate.Invoke(salt, encoding.GetBytes(password), hashed));
 }
        public void Provided_Password_Does_Not_Match_User_Password()
        {
            string providedPassword = "******";

            string hashedProvidedPassword = PasswordEncoder.Encode(providedPassword);
            string hashedUserPassword     = PasswordEncoder.Encode(_user.Password);

            bool result = PasswordComparer.ComparePasswords(hashedProvidedPassword, hashedUserPassword);

            Assert.IsFalse(result);
        }
        public void Provided_Password_Matches_User_Password()
        {
            string providedPassword = "******";

            string hashedProvidedPassword = PasswordEncoder.Encode(providedPassword);
            string hashedUserPassword     = PasswordEncoder.Encode(_user.Password);

            bool result = PasswordComparer.ComparePasswords(hashedProvidedPassword, hashedUserPassword);

            Assert.IsTrue(result);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Compare a given salt and password to a previously hashed password.
 /// </summary>
 /// <param name="delegate">The current <see cref="PasswordComparer"/> implementation.</param>
 /// <param name="salt">A sequence of bytes representing the salt.</param>
 /// <param name="password">A sequence of bytes representing the clear password.</param>
 /// <param name="hashed">
 /// A sequence of bytes representing a previous result of hashing a salt and password.
 /// </param>
 /// <returns>
 /// A value indicating whether or not the given salt and password equals the given hashed password.
 /// </returns>
 public static bool Compare(this PasswordComparer @delegate, byte[] salt, byte[] password, byte[] hashed)
 {
     return(@delegate.Invoke(salt, password, hashed));
 }