public Guid GetUserKeyByUsernameAndPassword(string username, string password)
        {
            Guid userKey           = new Guid();
            var  getUserByUsername = AyudaContext.User.Where(w => w.Username == username).FirstOrDefault();

            if (getUserByUsername != null)
            {
                if (SecurePasswordHelper.Verify(password, getUserByUsername.Password))
                {
                    userKey = new Guid(getUserByUsername.UserKey.ToString());
                }
            }
            return(userKey);
        }
        public int GetUserIdByUsernameAndPassword(string username, string password)
        {
            int userId            = 0;
            var getUserByUsername = AyudaContext.User.Where(w => w.Username == username).FirstOrDefault();

            if (getUserByUsername != null)
            {
                if (SecurePasswordHelper.Verify(password, getUserByUsername.Password))
                {
                    userId = getUserByUsername.UserId;
                }
            }
            return(userId);
        }
예제 #3
0
        public override bool UpdateUserPassword()
        {
            bool result = false;

            if (userKey.ToString().Length == 36 && !string.IsNullOrEmpty(oldPassword) && !string.IsNullOrEmpty(newPassword))
            {
                using (var userUnitOfWork = new UserUnitOfWork(new AyudaContext()))
                {
                    var user = userUnitOfWork.Users.GetUserByUserKey(userKey);
                    if (user.UserId > 0)
                    {
                        if (SecurePasswordHelper.Verify(oldPassword, user.Password))
                        {
                            user.Password = SecurePasswordHelper.Hash(newPassword);
                            userUnitOfWork.Users.Update(user);
                            result = userUnitOfWork.Complete() > 0;
                            userUnitOfWork.Dispose();
                        }
                    }
                }
            }
            return(result);
        }
        public UserCredential GetUserCredentialByUsernameAndPassword(string username, string password)
        {
            var userCredential    = new UserCredential();
            var getUserByUsername = AyudaContext.User.Where(w => w.Username == username).FirstOrDefault();

            if (getUserByUsername.UserKey.ToString().Length == 36)
            {
                if (SecurePasswordHelper.Verify(password, getUserByUsername.Password))
                {
                    var userLogin = new UserLogin
                    {
                        UserId         = getUserByUsername.UserId,
                        LoginTime      = DateTime.Now,
                        LogoutTime     = null,
                        ExpirationDate = DateTime.Now.AddMinutes(Convert.ToInt32(JsonHelper.GetJsonValue("Token:ExpirationMinutes")))
                    };
                    AyudaContext.UserLogin.Add(userLogin);
                    if (AyudaContext.SaveChanges() > 0)
                    {
                        var getUserProfile = AyudaContext.UserProfile.Where(w => w.UserId == getUserByUsername.UserId).FirstOrDefault();
                        if (getUserProfile.UserProfileId > 0)
                        {
                            userCredential.UserID = getUserByUsername.UserId;
                        }
                        userCredential.Username      = getUserByUsername.Username;
                        userCredential.UserKey       = new Guid(getUserByUsername.UserKey.ToString());
                        userCredential.EmailAddress  = getUserByUsername.EmailAddress;
                        userCredential.ContactNumber = getUserByUsername.ContactNumber;
                        userCredential.LoginKey      = new Guid(userLogin.LoginKey.ToString());
                        userCredential.UserLoginId   = userLogin.UserLoginId;
                        userCredential.UserType      = (int)getUserByUsername.UserType;
                        userCredential.BirthDate     = getUserProfile.BirthDate;
                    }
                }
            }
            return(userCredential);
        }