Exemple #1
0
        public bool Equals(PlaintextPassword pt)
        {
            if ((object)pt == null)
            {
                return(false);
            }
            //faz o hash do plaintext
            string ptHash = Pbkdf2Hash(pt.Plaintext, _b64salt, _hashIters);

            if (ptHash == _b64hash)
            {
                return(true);
            }

            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Autentica um par (email, senha) com o banco de dados.
        /// </summary>
        /// <param name="email">E-mail</param>
        /// <param name="password">Senha em texto claro</param>
        /// <param name="dbUser">Usuário autenticado</param>
        /// <returns></returns>
        public bool Authenticate(string email, string password, out NimbusPrincipal principal, out AuthenticationResult authDetails)
        {
            principal = null;

            using (var db = _dbFactory.OpenDbConnection())
            {
                var dbuser = db.Where <User>(u => u.Email == email).FirstOrDefault();
                if (dbuser == null)
                {
                    authDetails = AuthenticationResult.UserDoesNotExist;
                    return(false); //Usuário não existe.
                }

                if (dbuser.Password == null)
                {
                    authDetails = AuthenticationResult.UserRemoved;
                    return(false);
                }

                NSPHash           hashedPassword = new NSPHash(dbuser.Password);
                PlaintextPassword ptPassword     = new PlaintextPassword(password);

                if (hashedPassword.Equals(ptPassword))
                {
                    //preenche o NimbusUser
                    principal   = GetNimbusPrincipal(dbuser);
                    authDetails = AuthenticationResult.InvalidPassword;
                    return(true);
                }
                else
                {
                    authDetails = AuthenticationResult.InvalidPassword;
                    return(false);
                }
            }

            authDetails = AuthenticationResult.GenericFail;
            return(false);
        }