Exemple #1
0
        private ResetPasswordResponse GenerateToken(ResetPasswordRequest request)
        {
            var response = new ResetPasswordResponse();

            ///Try to save token to database
            try
            {
                response.Salt = crypto.Salt != null ? crypto.Salt : crypto.GenerateSalt(crypto.HashIterations, crypto.SaltSize);

                response.Email = request.Email;
                response.ExpireDate = DateTime.Now.AddDays(3);
                response.Token = crypto.Compute(request.Email, response.Salt);
                //var entity = new ResetPassword { Email = response.Email, Token = response.Token, Salt = response.Salt, ExpireDate = response.ExpireDate };
                var entity = response.MapTo<ResetPassword>();
                DataContext.ResetPasswords.Add(entity);
                DataContext.SaveChanges();
                response.IsSuccess = true;
                response.Message = "Password Token Successfully Created";
            }
            catch (System.InvalidOperationException x)
            {
                return new ResetPasswordResponse
                {
                    IsSuccess = false,
                    Message = x.Message
                };
            }
            return response;
        }
Exemple #2
0
 public ResetPasswordResponse ResetPassword(ResetPasswordRequest request)
 {
     var response = new ResetPasswordResponse();
     response = this.GenerateToken(request);
     return response;
 }