Beispiel #1
0
        public static Password Create(string plainPassword)
        {
            if (string.IsNullOrEmpty(plainPassword))
            {
                throw new ArgumentException("password should not be empty");
            }

            if (plainPassword.Length < 6)
            {
                throw new ArgumentException("Customer name is too short");
            }

            return(new Password(HashManagement.Md5Hash(plainPassword)));
        }
 public static UserData GetUserData(RegisterViewModel registerViewModel)
 {
     return(new UserData
     {
         FirstName = registerViewModel.FirstName,
         LastName = registerViewModel.LastName,
         Email = registerViewModel.EmailAddress,
         MobileNumber = registerViewModel.MobileNumber,
         Company = registerViewModel.Company,
         Skill = registerViewModel.Skill,
         Password = HashManagement.Md5Hash(registerViewModel.Password),
         CreateDate = DateTime.Now
     });
 }
Beispiel #3
0
        public object Login(LoginViewModel loginViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new BaseResponse(ResponseStatus.ValidationError.ToString(), ModelState.Values.ToList()[0].Errors[0].ErrorMessage)));
            }

            if (!_accountLogic.IsUserExist(loginViewModel.Username, HashManagement.Md5Hash(loginViewModel.Password)))
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, new BaseResponse(ResponseStatus.ValidationError.ToString(), ResponseMessagesModel.UsernameOrPassIsWrong)));
            }

            UserData userData = _accountLogic.GetUser(loginViewModel.Username);

            return(Request.CreateResponse(HttpStatusCode.OK, new BaseResponse(ResponseStatus.Success.ToString(), ResponseMessagesModel.Success, _tokenHelper.CreateUserToken(userData))));
        }
Beispiel #4
0
        public static TokenInformation CreateVerificationToken(Guid userId)
        {
            string verificationToken = HashManagement.Md5Hash($"{userId}{DateTime.Now}");

            return(new TokenInformation(DateTime.Now.AddMinutes(3), verificationToken));
        }