Ejemplo n.º 1
0
        public IUser LoginUser(IUser user)
        {
            try
            {
                IUser DBuser = this.GetUserByUsername(user.Username);

                if (DBuser == null)
                {
                    throw new Exception("LoginError_User_Not_Found");
                }

                bool userIsVerified = HandlerFactory.GetLoginHandler().VerifyPasswordHash(user.UserPassword, DBuser.UserPassword, DBuser.Salt);

                if (userIsVerified)
                {
                    user.UserPassword = null;
                    user.Salt         = null;

                    return(user);
                }
                else
                {
                    throw new Exception("LoginError_Password_Incorrect");
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Ejemplo n.º 2
0
        public void CreateUser(IUser user)
        {
            IHashedUser hashedUser = HandlerFactory.GetLoginHandler().CreateHashedUserInfo(user.Username, user.UserPassword);

            user.UserPassword = hashedUser.Password;
            user.Salt         = hashedUser.Salt;

            using (var conn = new SqlConnection(HandlerFactory.GetDBConnectionString()))
            {
                conn.Open();
                var identity = conn.Insert(user);
                conn.Close();
            }
        }