/// <summary> /// Reset password. /// </summary> /// <param name="username">The username.</param> /// <param name="answer">The answer.</param> /// <returns>The new password.</returns> public string ResetPassword(string username, string answer) { // Get the user data. Nequeo.DataAccess.ApplicationLogin.Data.User user = GetSpecificUser(username); if (!EnablePasswordReset) { throw new NotSupportedException("Password reset is not enabled."); } if (user == null) { throw new NotSupportedException("The supplied user name has not been found."); } // Generate the new password. string newPassword = System.Web.Security.Membership.GeneratePassword(MinRequiredPasswordLength, MinRequiredNonAlphanumericCharacters); // Update the password. user.LoginPassword = newPassword; user.ModifiedDate = DateTime.Now; bool ret = new Nequeo.DataAccess.ApplicationLogin.Data.Extension.User().Update.UpdateItem(user); // Return the password. if (ret) { return(newPassword); } else { throw new Exception("User not found, or user is locked out. Password not Reset."); } }
/// <summary> /// Validate the user. /// </summary> /// <param name="username">The username.</param> /// <param name="password">The password.</param> /// <returns>True if complete; else false.</returns> public bool ValidateUser(string username, string password) { bool isValid = false; // Attempt to validate the user. Nequeo.DataAccess.ApplicationLogin.Data.User user = GetSpecificUser(username); // User maybe suspended (LockedOut). if (user != null) { // If user is suspended. if (user.UserSuspended) { isValid = false; } else { // Check the password format. if (CheckPassword(password, user.LoginPassword)) { // User is valid. isValid = true; // Update the user data. user.ModifiedDate = DateTime.Now; new Nequeo.DataAccess.ApplicationLogin.Data.Extension.User().Update.UpdateItem(user); } } } // Return true if valid else false. return(isValid); }
/// <summary> /// Get username by email. /// </summary> /// <param name="email">The email address.</param> /// <returns>The username; else empty string.</returns> public string GetUserNameByEmail(string email) { string username = string.Empty; // Get the user data. Nequeo.DataAccess.ApplicationLogin.Data.Extension.User user = new Nequeo.DataAccess.ApplicationLogin.Data.Extension.User(); Nequeo.DataAccess.ApplicationLogin.Data.Extension.UserAddress userAddress = new Nequeo.DataAccess.ApplicationLogin.Data.Extension.UserAddress(); Nequeo.DataAccess.ApplicationLogin.Data.UserAddress address = userAddress.Select.SelectDataEntity(u => u.EmailAddress == email); Nequeo.DataAccess.ApplicationLogin.Data.User userData = user.Select.SelectDataEntity(u => u.UserAddressID == address.UserAddressID); // Return the username. if (userData != null) { username = userData.LoginUsername; } // Return an empty string. if (userData == null) { username = string.Empty; } // Return the username. return(username); }
/// <summary> /// Get password. /// </summary> /// <param name="username">The username.</param> /// <param name="answer">The answer.</param> /// <returns>The password.</returns> public string GetPassword(string username, string answer) { if (!EnablePasswordRetrieval) { throw new Exception("Password Retrieval Not Enabled."); } if (PasswordFormat == System.Web.Security.MembershipPasswordFormat.Hashed) { throw new Exception("Cannot retrieve Hashed passwords."); } // Get the user data. Nequeo.DataAccess.ApplicationLogin.Data.User user = GetSpecificUser(username); if (user == null) { throw new NotSupportedException("The supplied user name has not been found."); } // Assing the password data. string password = user.LoginPassword; // Unencode the password. if (PasswordFormat == System.Web.Security.MembershipPasswordFormat.Encrypted) { password = UnEncodePassword("", password); } // Return the password. return(password); }
/// <summary> /// Delete the user /// </summary> /// <param name="username">The username.</param> /// <param name="deleteAllRelatedData">Delete all related data.</param> /// <returns>True if complete; else false.</returns> public bool DeleteUser(string username, bool deleteAllRelatedData) { bool ret = false; // Get the user data. Nequeo.DataAccess.ApplicationLogin.Data.User user = GetSpecificUser(username); try { // Attempt to delete the user. ret = new Nequeo.DataAccess.ApplicationLogin.Data.Extension.User(). Delete.DeleteItemPredicate( u => (u.LoginUsername == username) ); // Delete any extra data. if (deleteAllRelatedData) { // Attempt to delete the user address. ret = new Nequeo.DataAccess.ApplicationLogin.Data.Extension.UserAddress(). Delete.DeleteItemPredicate( u => (u.UserAddressID == user.UserAddressID) ); } } catch { } // Return the result of the deletion. return(ret); }
/// <summary> /// Change password. /// </summary> /// <param name="username">The username.</param> /// <param name="oldPassword">The old password.</param> /// <param name="newPassword">The new password.</param> /// <returns>True if complete; else false.</returns> public bool ChangePassword(string username, string oldPassword, string newPassword) { // Validate the user. if (!ValidateUser(username, oldPassword)) { return(false); } bool ret = false; // Attempt to validate the user. Nequeo.DataAccess.ApplicationLogin.Data.User user = GetSpecificUser(username); // If user exists. if (user != null) { // Update the question and answer. ret = new Nequeo.DataAccess.ApplicationLogin.Data.Extension.User(). Update.UpdateItemPredicate( new Data.User() { LoginPassword = newPassword, ModifiedDate = DateTime.Now }, u => (u.LoginUsername == username) ); } // Return the result. return(ret); }
/// <summary> /// Get the specific user for the current application. /// </summary> /// <param name="userID">The userid.</param> /// <returns>The user; else null.</returns> private Nequeo.DataAccess.ApplicationLogin.Data.User GetSpecificUser(long userID) { // Get the user data. Nequeo.DataAccess.ApplicationLogin.Data.Extension.User userExt = new Nequeo.DataAccess.ApplicationLogin.Data.Extension.User(); Nequeo.DataAccess.ApplicationLogin.Data.User user = userExt.Select.SelectDataEntity( u => (u.UserID == userID) ); // Return the user. return(user); }
/// <summary> /// Get the specific user for the current application. /// </summary> /// <param name="username">The username.</param> /// <returns>The user; else null.</returns> private Nequeo.DataAccess.ApplicationLogin.Data.User GetSpecificUser(string username) { // Get the user data. Nequeo.DataAccess.ApplicationLogin.Data.Extension.User userExt = new Nequeo.DataAccess.ApplicationLogin.Data.Extension.User(); Nequeo.DataAccess.ApplicationLogin.Data.User user = userExt.Select.SelectDataEntity( u => (u.LoginUsername.ToLower() == username.ToLower()) ); // Return the user. return(user); }
/// <summary> /// Unlock the user. /// </summary> /// <param name="userName">The username.</param> /// <returns>True if complete; else false.</returns> public bool UnlockUser(string userName) { bool ret = false; // Get the user data. Nequeo.DataAccess.ApplicationLogin.Data.User user = GetSpecificUser(userName); // Update the user. if (user != null) { user.UserSuspended = false; ret = new Nequeo.DataAccess.ApplicationLogin.Data.Extension.User().Update.UpdateItem(user); } // Return the result. return(ret); }
/// <summary> /// Get user. /// </summary> /// <param name="username">The username.</param> /// <param name="userIsOnline">Is the user online.</param> /// <returns>The membership user.</returns> public System.Web.Security.MembershipUser GetUser(string username, bool userIsOnline) { System.Web.Security.MembershipUser memShipUser = null; DateTime createdDate = DateTime.Now; // Get the user data. Nequeo.DataAccess.ApplicationLogin.Data.User user = GetSpecificUser(username); Nequeo.DataAccess.ApplicationLogin.Data.Extension.UserAddress userAddress = new Nequeo.DataAccess.ApplicationLogin.Data.Extension.UserAddress(); // Make sure that the user exists. if (user != null) { // Get the current users address details Data.UserAddress address = userAddress.Select.SelectDataEntity(u => u.UserAddressID == user.UserAddressID); // Create the membership user. memShipUser = new System.Web.Security.MembershipUser( ProviderName, username, user.UserID, address.EmailAddress, "", user.Comments, true, user.UserSuspended, createdDate, createdDate, createdDate, createdDate, createdDate); // If user is on line. if (userIsOnline) { user.ModifiedDate = createdDate; bool ret = new Nequeo.DataAccess.ApplicationLogin.Data.Extension.User().Update.UpdateItem(user); } } // Return the membership user. return(memShipUser); }
/// <summary> /// Update the user. /// </summary> /// <param name="user">The membership user.</param> public void UpdateUser(System.Web.Security.MembershipUser user) { // Get the user data. Nequeo.DataAccess.ApplicationLogin.Data.User userData = GetSpecificUser(user.UserName); // Update the user. if (user != null) { new Nequeo.DataAccess.ApplicationLogin.Data.Extension.User(). Update.UpdateItemPredicate( new Data.User() { LoginPassword = userData.LoginPassword, ModifiedDate = user.LastLoginDate, UserSuspended = user.IsLockedOut }, u => (u.LoginUsername == user.UserName) ); } }