public override bool HasLocalAccount(int userId) { using (var session = DocumentStore.OpenSession()) { return(BirdBrainHelper.GetUserById(userId, session) != null); } }
public override int GetUserIdFromPasswordResetToken(string token) { using (var session = DocumentStore.OpenSession()) { var user = BirdBrainHelper.GetUserByPasswordResetToken(token, session); return(user != null ? user.Id : -1); } }
public override bool ConfirmAccount(string accountConfirmationToken) { using (var session = DocumentStore.OpenSession()) { var user = BirdBrainHelper.GetUserByConfirmationToken(accountConfirmationToken, session); return(ConfirmAccount(accountConfirmationToken, user, session)); } }
public override int GetPasswordFailuresSinceLastSuccess(string userName) { using (var session = DocumentStore.OpenSession()) { var user = BirdBrainHelper.GetUserByUsername(userName, session); return(user != null ? user.PasswordFailuresSinceLastSuccess : 0); } }
public override DateTime GetLastPasswordFailureDate(string userName) { using (var session = DocumentStore.OpenSession()) { var user = BirdBrainHelper.GetUserByUsername(userName, session); return(user != null ? user.LastPasswordFailures : DateTime.MinValue); } }
public override bool IsUserInRole(string username, string roleName) { using (var session = documentStore.OpenSession()) { var user = BirdBrainHelper.GetUserByUsername(username, session); return(user.Roles.Contains(roleName)); } }
public override bool IsConfirmed(string userName) { using (var session = DocumentStore.OpenSession()) { var user = BirdBrainHelper.GetUserByUsername(userName, session); return(user != null && user.IsApproved); } }
public override string[] GetRolesForUser(string username) { using (var session = documentStore.OpenSession()) { var user = BirdBrainHelper.GetUserByUsername(username, session); return(user != null ? user.Roles : new string[] {}); } }
public override bool DeleteAccount(string userName) { using (var session = DocumentStore.OpenSession()) { var user = BirdBrainHelper.GetUserByUsername(userName, session); if (user != null) { session.Delete(user); session.SaveChanges(); return(true); } return(false); } }
public override bool ChangePassword(string username, string oldPassword, string newPassword) { using (var session = documentStore.OpenSession()) { var user = BirdBrainHelper.GetUserByUsernameAndPassword(username, HashPassword(oldPassword), session); if (user != null) { user.Password = HashPassword(newPassword); user.LastPasswordChange = DateTime.Now; session.SaveChanges(); return(true); } return(false); } }
public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer) { using (var session = documentStore.OpenSession()) { var user = BirdBrainHelper.GetUserByUsernameAndPassword(username, HashPassword(password), session); if (user != null) { user.PasswordQuestion = newPasswordQuestion; user.PasswordAnswer = newPasswordAnswer; session.SaveChanges(); return(true); } return(false); } }
public override string GeneratePasswordResetToken(string userName, int tokenExpirationInMinutesFromNow) { using (var session = DocumentStore.OpenSession()) { var user = BirdBrainHelper.GetUserByUsername(userName, session); if (user != null) { user.PasswordResetToken = Guid.NewGuid().ToString(); user.PasswordResetTokenExpiry = DateTime.Now.Add(TimeSpan.FromMinutes(tokenExpirationInMinutesFromNow)); session.SaveChanges(); return(user.PasswordResetToken); } return(null); } }
public override string ResetPassword(string username, string answer) { using (var session = documentStore.OpenSession()) { var user = BirdBrainHelper.GetUserByUsernameAndAnswer(username, answer, session); if (user != null) { var password = Membership.GeneratePassword(MinRequiredPasswordLength, MinRequiredNonAlphanumericCharacters); user.Password = HashPassword(password); user.LastPasswordChange = DateTime.Now; session.SaveChanges(); return(password); } throw new MembershipPasswordException("Unable to reset password."); } }
public override bool ResetPasswordWithToken(string token, string newPassword) { using (var session = DocumentStore.OpenSession()) { var user = BirdBrainHelper.GetUserByPasswordResetToken(token, session); if (user != null) { user.Password = BirdBrainMembershipProvider.HashPassword(newPassword); user.PasswordResetTokenExpiry = DateTime.MinValue; user.LastPasswordChange = DateTime.Now; session.SaveChanges(); return(true); } return(false); } }
public override MembershipUser GetUser(string username, bool userIsOnline) { using (var session = documentStore.OpenSession()) { var user = BirdBrainHelper.GetUserByUsername(username, session); if (user != null) { if (userIsOnline) { user.LastActive = DateTime.Now; session.SaveChanges(); } return(new BirdBrainMembershipUser(user)); } return(null); } }
public override string CreateAccount(string userName, string password, bool requireConfirmationToken) { MembershipCreateStatus status; CreateUser(userName, password, null, null, null, !requireConfirmationToken, null, out status); if (status.Equals(MembershipCreateStatus.Success) && requireConfirmationToken) { using (var session = DocumentStore.OpenSession()) { var user = BirdBrainHelper.GetUserByUsername(userName, session); user.ConfirmationToken = Guid.NewGuid().ToString(); session.SaveChanges(); return(user.ConfirmationToken); } } return(null); }
public override string CreateAccount(string userName, string password, bool requireConfirmationToken) { MembershipCreateStatus status; CreateUser(userName, password, null, null, null, !requireConfirmationToken, null, out status); if (status.Equals(MembershipCreateStatus.Success) && requireConfirmationToken) { using (var session = DocumentStore.OpenSession()) { session.Query <User>() .Customize(a => a.WaitForNonStaleResultsAsOfLastWrite()) .First(u => u.Username == userName); var user = BirdBrainHelper.GetUserByUsername(userName, session); user.ConfirmationToken = Guid.NewGuid().ToString(); session.SaveChanges(); return(user.ConfirmationToken); } } return(null); }
public override bool ValidateUser(string username, string password) { using (var session = documentStore.OpenSession()) { var user = BirdBrainHelper.GetUserByUsernameAndPassword(username, HashPassword(password), session); if (user != null) { user.LastActive = DateTime.Now; user.LastLogin = DateTime.Now; session.SaveChanges(); return(true); } user = BirdBrainHelper.GetUserByUsername(username, session); if (user != null) { user.PasswordFailuresSinceLastSuccess += 1; user.LastPasswordFailures = DateTime.Now; session.SaveChanges(); } return(false); } }