Beispiel #1
0
        public Login ChangePassword(int id, string newPassword)
        {
            using (LoanPriceEntities context = new LoanPriceEntities())
            {
                Login model = context.Logins.FirstOrDefault(c => c.ID == id);

                // Save password history
                PasswordHistory history = new PasswordHistory();
                history.ChangedDate = DateTime.Now;
                history.ChangedPassword = newPassword;
                history.Password = model.Password;
                history.UserId = model.ID;

                context.PasswordHistories.AddObject(history);

                model.Password = newPassword;

                context.SaveChanges();
                return model;
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the PasswordHistories EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPasswordHistories(PasswordHistory passwordHistory)
 {
     base.AddObject("PasswordHistories", passwordHistory);
 }
Beispiel #3
0
        public Login ResetPasswordPublic(string userName, string newPassword, out string message)
        {
            using (LoanPriceEntities context = new LoanPriceEntities())
            {
                Login model = context.Logins.FirstOrDefault(c => c.Name == userName);
                if (model == null)
                {
                    message = "User with this name doesn't exist";
                    return model;
                }
                else if (model.IsLocked)
                {
                    message = "User account is locked. We cann't reset password.";
                    return model;
                }
                // Save password history
                PasswordHistory history = new PasswordHistory();
                history.ChangedDate = DateTime.Now;
                history.ChangedPassword = newPassword;
                history.Password = model.Password;
                history.UserId = model.ID;

                context.PasswordHistories.AddObject(history);

                model.Password = newPassword;
                model.LastPasswordReset = DateTime.Now;
                context.SaveChanges();
                message = "Password reseted successfully";
                return model;
            }
        }
 /// <summary>
 /// Create a new PasswordHistory object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="userId">Initial value of the UserId property.</param>
 /// <param name="password">Initial value of the Password property.</param>
 /// <param name="changedPassword">Initial value of the ChangedPassword property.</param>
 /// <param name="changedDate">Initial value of the ChangedDate property.</param>
 public static PasswordHistory CreatePasswordHistory(global::System.Int32 id, global::System.Int32 userId, global::System.String password, global::System.String changedPassword, global::System.DateTime changedDate)
 {
     PasswordHistory passwordHistory = new PasswordHistory();
     passwordHistory.ID = id;
     passwordHistory.UserId = userId;
     passwordHistory.Password = password;
     passwordHistory.ChangedPassword = changedPassword;
     passwordHistory.ChangedDate = changedDate;
     return passwordHistory;
 }