public string VerifyUser2(string userName, string userPassword, string systemType, string ip, string macAddr) { string str = ""; if (string.IsNullOrEmpty(systemType)) { str = "系统禁止授权此应用"; } else { UserInfo userByName = this.GetUserByName(userName); if (!((userByName == null) || userByName.IsExpire)) { userPassword = EncryptHelper.ComputeHash(userPassword, userName.ToLower()); if (userPassword == userByName.Password) { iuser_0.UpdateUserLoginData(userByName.ID, ip, macAddr); BLLFactory <LoginLog> .Instance.AddLoginLog(userByName, systemType, ip, macAddr, "用户登录"); } else { str = "用户密码输入错误"; } } else { str = "用户名输入错误或者您已经被禁用"; } } return(str); }
public override bool Insert(UserInfo obj) { UserInfo info = obj; info.Password = EncryptHelper.ComputeHash(info.Password, info.Name.ToLower()); return(base.Insert(obj)); }
public override bool Insert(UserInfo obj, DbTransaction trans = null) { UserInfo info = (UserInfo)obj; info.Password = EncryptHelper.ComputeHash(UserInfo.DefaultPassword, info.Name.ToLower()); return(base.Insert(obj, trans)); }
public async Task <IActionResult> ResetPassword([FromBody] AccountResetPasswordInfo info, CancellationToken token) { if (info == null || string.IsNullOrEmpty(info.AccountName)) { throw new UCenterException(UCenterErrorCode.AccountNotExist); } var accountEntity = await this.Database.Accounts.GetSingleAsync(a => a.AccountName == info.AccountName, token); if (accountEntity == null) { throw new UCenterException(UCenterErrorCode.AccountNotExist); } if (!EncryptHelper.VerifyHash(info.SuperPassword, accountEntity.SuperPassword)) { await this.TraceAccountErrorAsync( accountEntity, UCenterErrorCode.AccountPasswordUnauthorized, "The super password provided is incorrect", token); throw new UCenterException(UCenterErrorCode.AccountPasswordUnauthorized); } accountEntity.Password = EncryptHelper.ComputeHash(info.Password); await this.Database.Accounts.UpsertAsync(accountEntity, token); await this.TraceAccountEvent(accountEntity, "ResetPassword", token : token); return(this.CreateSuccessResult(this.ToResponse <AccountResetPasswordResponse>(accountEntity))); }
/// <summary> /// 根据用户名、密码验证用户身份有效性 /// </summary> /// <param name="userName">用户名称</param> /// <param name="userPassword">用户密码</param> /// <param name="systemType">系统类型ID</param> /// <param name="ip">IP地址</param> /// <param name="macAddr">Mac网卡地址</param> /// <returns></returns> public string VerifyUser(string userName, string userPassword, string systemType, string ip, string macAddr) { if (string.IsNullOrEmpty(systemType)) { return(""); } string identity = ""; UserInfo userInfo = this.GetUserByName(userName); if (userInfo != null && !userInfo.IsExpire && !userInfo.Deleted) { bool ipAccess = BLLFactory <BlackIP> .Instance.ValidateIPAccess(ip, userInfo.ID); if (ipAccess) { userPassword = EncryptHelper.ComputeHash(userPassword, userName.ToLower()); if (userPassword == userInfo.Password) { //更新用户的登录时间和IP地址 this.userDal.UpdateUserLoginData(userInfo.ID, ip, macAddr); identity = EncryptHelper.EncryptStr(userName + Convert.ToString(Convert.ToChar(1)) + userPassword, systemType); //记录用户登录日志 BLLFactory <LoginLog> .Instance.AddLoginLog(userInfo, systemType, ip, macAddr, "用户登录"); } } else { BLLFactory <LoginLog> .Instance.AddLoginLog(userInfo, systemType, ip, macAddr, "用户登录操作被黑白名单禁止登陆!"); } } return(identity); }
public override bool Update(UserInfo obj, object primaryKeyValue, DbTransaction trans = null) { if (obj.Password.Length < 50) { obj.Password = EncryptHelper.ComputeHash(obj.Password, obj.Name.ToLower()); } return(this.userDal.Update(obj, primaryKeyValue, trans)); }
public override bool Update(UserInfo obj, object primaryKeyValue) { UserInfo info = obj; if (info.Password.Length < 50) { info.Password = EncryptHelper.ComputeHash(info.Password, info.Name.ToLower()); } return(this.iuser_0.Update(info, primaryKeyValue)); }
/// <summary> /// 根据用户名、密码验证用户身份有效性 /// </summary> /// <param name="userName">用户名称</param> /// <param name="userPassword">用户密码</param> /// <param name="systemType">系统类型ID</param> /// <param name="ip">IP地址</param> /// <param name="macAddr">Mac网卡地址</param> /// <returns></returns> public string VerifyUser(string userName, string userPassword, string systemType, string ip, string macAddr) { if (string.IsNullOrEmpty(systemType)) { return(""); } string identity = ""; UserInfo userInfo = this.GetUserByName(userName); if (userInfo != null && !userInfo.IsExpire && !userInfo.Deleted) { //还需要判断是否在有效期内 var expireDate = userInfo.ExpireDate; if (expireDate.HasValue && expireDate.Value < DateTime.Now) { //处理非管理员外的失效设置 if (userInfo.Name != "admin") { Hashtable ht = new Hashtable(); ht.Add("IsExpire", 1); //设置失效 BLLFactory <User> .Instance.UpdateFields(ht, userInfo.ID); //更新过期设置 } } else { bool ipAccess = BLLFactory <BlackIP> .Instance.ValidateIPAccess(ip, userInfo.ID); if (ipAccess) { userPassword = userPassword ?? "";//如果为null,那么密码为空字符串 userPassword = EncryptHelper.ComputeHash(userPassword, userName.ToLower()); if (userPassword == userInfo.Password) { //更新用户的登录时间和IP地址 this.userDal.UpdateUserLoginData(userInfo.ID, ip, macAddr); identity = EncryptHelper.EncryptStr(userName + Convert.ToString(Convert.ToChar(1)) + userPassword, systemType); //记录用户登录日志 BLLFactory <LoginLog> .Instance.AddLoginLog(userInfo, systemType, ip, macAddr, "用户登录"); } } else { BLLFactory <LoginLog> .Instance.AddLoginLog(userInfo, systemType, ip, macAddr, "用户登录操作被黑白名单禁止登录!"); } } } return(identity); }
public bool ModifyPassword(string userName, string userPassword, string systemType, string ip, string macAddr) { bool flag = false; UserInfo userByName = this.GetUserByName(userName); if (userByName != null) { userPassword = EncryptHelper.ComputeHash(userPassword, userName.ToLower()); userByName.Password = userPassword; userByName.LastPasswordTime = DateTime.Now; if (flag = this.iuser_0.Update(userByName, userByName.ID.ToString())) { BLLFactory <LoginLog> .Instance.AddLoginLog(userByName, systemType, ip, macAddr, "用户修改密码"); } } return(flag); }
public async Task <bool> RegisterUser(UserInfo userInfo) { if (userInfo != null) { var dbInfo = await _gameJiJiaRepository.GetUserInfo(userInfo.AccountId); if (dbInfo != null) { return(false); } var encryptPassword = EncryptHelper.ComputeHash(userInfo.Password); userInfo.Password = encryptPassword; return(await _gameJiJiaRepository.RegisterUser(userInfo)); } return(false); }
/// <summary> /// 修改用户密码 /// </summary> /// <param name="userName">修改用户名</param> /// <param name="userPassword">用户密码(未加密)</param> /// <param name="systemType">系统类型</param> /// <param name="ip">IP地址</param> /// <param name="macAddr">Mac地址</param> /// <returns></returns> public bool ModifyPassword(string userName, string userPassword, string systemType, string ip, string macAddr) { bool result = false; UserInfo userByName = this.GetUserByName(userName); if (userByName != null) { userPassword = EncryptHelper.ComputeHash(userPassword, userName.ToLower()); userByName.Password = userPassword; result = userDal.Update(userByName, userByName.ID.ToString()); if (result) { //记录用户修改密码日志 BLLFactory <LoginLog> .Instance.AddLoginLog(userByName, systemType, ip, macAddr, "用户修改密码"); } } return(result); }
public string VerifyUser(string userName, string userPassword, string systemType, string ip, string macAddr) { if (string.IsNullOrEmpty(systemType)) { return(""); } string str = ""; UserInfo userByName = this.GetUserByName(userName); if (!((userByName == null) || userByName.IsExpire)) { userPassword = EncryptHelper.ComputeHash(userPassword, userName.ToLower()); if (userPassword == userByName.Password) { iuser_0.UpdateUserLoginData(userByName.ID, ip, macAddr); str = EncryptHelper.EncryptStr(userName + Convert.ToString(Convert.ToChar(1)) + userPassword, systemType); BLLFactory <LoginLog> .Instance.AddLoginLog(userByName, systemType, ip, macAddr, "用户登录"); } } return(str); }
/// <summary> /// 管理员重置密码 /// </summary> /// <param name="loginUser_ID">登录账号ID</param> /// <param name="changeUser_ID">修改账号ID</param> /// <param name="ip">登录IP</param> /// <param name="macAddr">登录Mac地址</param> /// <returns></returns> public bool ResetPassword(int loginUser_ID, int changeUser_ID, string ip, string macAddr) { bool result = false; UserInfo loginInfo = this.FindByID(loginUser_ID); UserInfo changeInfo = this.FindByID(changeUser_ID); if (loginInfo != null && changeInfo != null) { string initPassword = EncryptHelper.ComputeHash(UserInfo.DefaultPassword, changeInfo.Name.ToLower()); changeInfo.Password = initPassword; result = userDal.Update(changeInfo, changeInfo.ID); if (result) { //记录用户修改密码日志 string message = string.Format("{0}重置了用户【{1}】的登录密码", loginInfo.FullName, changeInfo.FullName); BLLFactory <LoginLog> .Instance.AddLoginLog(loginInfo, "Security", ip, macAddr, message); } } return(result); }
public async Task <IActionResult> Register([FromBody] AccountRegisterRequestInfo info, CancellationToken token) { // 检测注册信息合法性 ValidateAccount(info); try { // 检测帐号名是否可以被注册 var oldAccountEntity = await this.Database.Accounts.GetSingleAsync( a => a.AccountName == info.AccountName, //|| a.Email == info.Email //|| a.Phone == info.Phone, token); if (oldAccountEntity != null) { throw new UCenterException(UCenterErrorCode.AccountNameAlreadyExist); } // 检查Device是否绑定了游客号 AccountEntity accountEntity = null; if (info != null && !string.IsNullOrEmpty(info.AppId) && info.Device != null && !string.IsNullOrEmpty(info.Device.Id)) { string guestDeviceId = $"{info.AppId}_{info.Device.Id}"; var guestDeviceEntity = await this.Database.GuestDevices.GetSingleAsync(guestDeviceId, token); if (guestDeviceEntity != null) { accountEntity = await this.Database.Accounts.GetSingleAsync(guestDeviceEntity.AccountId, token); } } bool guestConvert = true; if (accountEntity == null) { guestConvert = false; // 没有绑定游客号,正常注册 accountEntity = new AccountEntity { Id = Guid.NewGuid().ToString(), }; } accountEntity.AccountName = info.AccountName; accountEntity.AccountType = AccountType.NormalAccount; accountEntity.AccountStatus = AccountStatus.Active; accountEntity.Name = info.Name; accountEntity.Identity = info.Identity; accountEntity.Password = EncryptHelper.ComputeHash(info.Password); accountEntity.SuperPassword = EncryptHelper.ComputeHash(info.SuperPassword); accountEntity.Phone = info.Phone; accountEntity.Email = info.Email; accountEntity.Gender = info.Gender; //var placeholders = new[] // { // this.GenerateKeyPlaceholder(accountEntity.AccountName, KeyType.Name, accountEntity.Id, accountEntity.AccountName), // this.GenerateKeyPlaceholder(accountEntity.Phone, KeyType.Phone, accountEntity.Id, accountEntity.AccountName), // this.GenerateKeyPlaceholder(accountEntity.Email, KeyType.Email, accountEntity.Id, accountEntity.AccountName) // }; //foreach (var placeholder in placeholders) //{ // if (!string.IsNullOrEmpty(placeholder.Name)) // { // await this.Database.KeyPlaceholders.InsertAsync(placeholder, token); // removeTempsIfError.Add(placeholder); // } //} if (guestConvert) { // 绑定了游客号,游客号转正 await this.Database.Accounts.UpsertAsync(accountEntity, token); try { await this.Database.GuestDevices.DeleteAsync( d => d.AppId == info.AppId && d.AccountId == accountEntity.Id, token); } catch (Exception ex) { CustomTrace.TraceError(ex, "Error to remove guest device"); } await this.TraceAccountEvent(accountEntity, "GuestConvert", token : token); } else { // 没有绑定游客号,正常注册 // Remove this from UCenter for performance concern // If user does not have default profile icon, app client should use local default one // accountEntity.ProfileImage = await this.storageContext.CopyBlobAsync( // accountEntity.Gender == Gender.Female ? this.settings.DefaultProfileImageForFemaleBlobName : this.settings.DefaultProfileImageForMaleBlobName, // this.settings.ProfileImageForBlobNameTemplate.FormatInvariant(accountEntity.Id), // token); // accountEntity.ProfileThumbnail = await this.storageContext.CopyBlobAsync( // accountEntity.Gender == Gender.Female // ? this.settings.DefaultProfileThumbnailForFemaleBlobName // : this.settings.DefaultProfileThumbnailForMaleBlobName, // this.settings.ProfileThumbnailForBlobNameTemplate.FormatInvariant(accountEntity.Id), // token); await this.Database.Accounts.InsertAsync(accountEntity, token); await TraceAccountEvent(accountEntity, "Register", info.Device, token : token); } if (info.Device != null) { await LogDeviceInfo(info.Device, token); } return(this.CreateSuccessResult(this.ToResponse <AccountRegisterResponse>(accountEntity))); } catch (Exception ex) { CustomTrace.TraceError(ex, "Account.Register Exception:AccoundName={info.AccountName}"); throw; } }