Ejemplo n.º 1
0
        public bool VerifyCredentials(string username, string password)
        {
            DBUser user = null;

            using (var conn = connFactory.OpenDbConnection()) {
                user = conn.FirstOrDefault <DBUser> (u => u.Username == username);
            }
            if (user == null)
            {
                return(false);
            }

            if (user.IsActivated == false)
            {
                throw new Rainy.ErrorHandling.UnauthorizedException()
                      {
                          UserStatus = "Moderation required",
                      };
            }

            //if (user.IsVerified == false)
            //	return false;

            var supplied_hash = user.ComputePasswordHash(password);

            if (supplied_hash == user.PasswordHash)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        public static bool UpdatePassword(this DBUser db_user, string password)
        {
            if (string.IsNullOrEmpty(db_user.PasswordSalt))
            {
                throw new ArgumentException("Salt must be set", "db_user");
            }

            // TODO update required keys?
            var hash = db_user.ComputePasswordHash(password);

            if (hash != db_user.PasswordHash)
            {
                db_user.PasswordHash = hash;
                return(true);
            }
            // same password, do nothing
            return(false);
        }