public void Register(RegisterCommand command) { ISecurityUtility securityUtility = new SecurityUtility(); ThrowError.Against <ArgumentException>(string.IsNullOrEmpty(command.UserName), String.Format(ErrorMessage.IsRequired, "Tên đăng nhập")); ThrowError.Against <ArgumentException>(string.IsNullOrEmpty(command.Password), String.Format(ErrorMessage.IsRequired, "Mật khẩu")); var user = securityUtility.GetUserByUsername(command.UserName); ThrowError.Against <ArgumentException>(user != null, String.Format(ErrorMessage.Exists, "Tên đăng nhập")); ThrowError.Against <ArgumentException>(_personService.Query(t => t.Email == command.Email).Select().Any(), String.Format(ErrorMessage.Exists, "Email")); // ThrowError.Against<ArgumentException>(!securityUtility.IsPasswordValid(command.Password), String.Format(ErrorMessage.IsPassword)); var person = new Person() { Email = command.Email, FullName = command.FullName, PersonId = Guid.NewGuid() }; user = new User() { Type = command.Type, UserName = command.UserName, CreationDate = DateTime.Now, Locked = false, PersonId = person.PersonId, Password = Cryptography.EncryptPassword(command.Password, "") }; _unitOfWork.Repository <Domain.Entity.User>().Insert(user); _personService.Insert(person); _unitOfWork.SaveChanges(); }
public override bool ValidateUser(string username, string password) { password = password.Trim(); var user = SecurityUtility.GetUserByUsername(username); if (user != null) { //// if (!user.Active || user.AccountLocked) //if (user.Locked) // return false; if (SecurityUtility.IsPasswordEqual(password, user.Password, user.Salt)) { //Stored valid logged user to session new UserSession(user); user.LastLoginTime = DateTime.Now; user.FailedLoginTimes = 0; SecurityUtility.UpdateUserInformation(user); return(true); } user.LastLoginTime = DateTime.Now; user.FailedLoginTimes++; SecurityUtility.UpdateUserInformation(user); } return(false); }
public override bool ChangePassword(string username, string oldPassword, string newPassword) { oldPassword = oldPassword.Trim(); if (!SecurityUtility.IsPasswordValid(newPassword)) { return(false); } var user = SecurityUtility.GetUserByUsername(username); if (user == null) { return(false); } var feedbackMessage = new System.Text.StringBuilder(); if (user.Password != oldPassword && user.Password != Cryptography.EncryptPassword(oldPassword, user.Salt)) { return(false); } user.Password = Cryptography.EncryptPassword(newPassword, user.Salt); IRepositoryProvider _repositoryProvider = new RepositoryProvider(new RepositoryFactories()); var unitofWork = new UnitOfWork(new MisukaDBContext(), _repositoryProvider); unitofWork.Repository <Domain.Entity.User>().Update(user); var ret = unitofWork.SaveChanges(); return(ret > 0); }
public override MembershipUser GetUser(string username, bool userIsOnline) { var user = SecurityUtility.GetUserByUsername(username); if (user != null) { var memUser = new MembershipUser(_providerName, username, user.PersonId, string.Empty, string.Empty, string.Empty, true, false, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.Now, DateTime.Now); return(memUser); } return(null); }
internal virtual void Init(string username, string password) { ISecurityUtility securityUtility = new SecurityUtility(); var membershipProvider = securityUtility.GetMembershipProvider(); if (!membershipProvider.ValidateUser(username, password)) { throw new ApplicationException(string.Format("Failed to init Session Object. Invalid username or password. Username: {0}. Password {1}", username, password)); } var user = SecurityUtility.GetUserByUsername(username); if (user == null) { throw new ApplicationException(string.Format("Cannot retrieve user for username {0}.", username)); } Init(user); }