public async Task <string> ChekcLoginCmdValidatableAsync(LoginCmd cmd, string clientIp, DateTime timeNow) { if (cmd.Account.IsNullOrWhiteSpace()) { return("账号不可为空"); } if (cmd.Password.IsNullOrWhiteSpace()) { return("密码不能为空"); } if (cmd.Password.Length > 30) { return("密码超长"); } if (!await _memberService.ExistAccountAsync(cmd.Account).ConfigureAwait(false)) { await _memberLoginLogService.NewLogAsync(new MemberLoginLog { Account = cmd.Account, Password = cmd.Password, CheckOn = timeNow, IsPass = false, Reason = "账号不存在", ClientIp = clientIp }).ConfigureAwait(false); return("账号不存在"); } var memberAccount = await _memberService.GetMemberAccountAsync(cmd.Account).ConfigureAwait(false); if (memberAccount.IsLockout) { await _memberLoginLogService.NewLogAsync(new MemberLoginLog { Account = cmd.Account, Password = cmd.Password, CheckOn = timeNow, IsPass = false, Reason = "账号被锁定", ClientIp = clientIp }).ConfigureAwait(false); return("账号被锁定"); } if (memberAccount.Password != HashGenerator.Encode(cmd.Password, memberAccount.PasswordFormat, memberAccount.PasswordSalt)) { await _memberLoginLogService.NewLogAsync(new MemberLoginLog { Account = cmd.Account, Password = cmd.Password, CheckOn = timeNow, IsPass = false, Reason = "密码不匹配", ClientIp = clientIp }).ConfigureAwait(false); return("密码不匹配"); } return(null); }
private async Task <Response> DoRenewPasswordAsync() { var cmd = this.Bind <RenewPasswordCmd>(); var timeNow = DateTime.Now; var err = await _loginValidatableService.CheckRenewPasswordCmdValidatableAsync(CurrentMemberId, cmd, ClientIP, timeNow).ConfigureAwait(false); if (!err.IsNullOrWhiteSpace()) { return(PreconditionFailed(err)); } var verificationCode = await _verificationCodeService.GetAvailableCode(CurrentMemberId, cmd.CheckCode, CodeType.RenewPassword).ConfigureAwait(false); await _verificationCodeService.UpdateVerificationCodeToDisabledByUsed(verificationCode.Id).ConfigureAwait(false); var passwordFormat = EnumHelper.Random(PasswordFormatType.None); var passwordSalt = HashGenerator.Salt(); var password = HashGenerator.Encode(cmd.Password, passwordFormat, passwordSalt); var accounts = await _memberService.GetMemberAccountsByMemberIdAsync(CurrentMemberId).ConfigureAwait(false); foreach (var item in accounts) { item.Password = password; item.PasswordSalt = passwordSalt; item.PasswordFormat = passwordFormat; await _memberService.UpdateMemberAccountAsync(item).ConfigureAwait(false); } return(Ok(new { message = $"密码已更新,请重新登录!" })); }
private async Task <Response> DoRegistAsync() { var cmd = this.Bind <RegistCmd>(); var timeNow = DateTime.Now; var err = await _loginValidatableService.CheckRegistCmdValidatableAsync(cmd, ClientIP, timeNow).ConfigureAwait(false); if (!err.IsNullOrWhiteSpace()) { return(PreconditionFailed(err)); } var verificationCode = await _verificationCodeService.GetAvailableCode(cmd.MobilePhone, cmd.CheckCode, cmd.CodeType).ConfigureAwait(false); await _verificationCodeService.UpdateVerificationCodeToDisabledByUsed(verificationCode.Id).ConfigureAwait(false); var entity = cmd.Adapt <MemberInfo>(); if (entity.Realname.IsNullOrWhiteSpace()) { entity.Realname = "待设定"; } entity.MobilePhone = cmd.MobilePhone; entity.Id = ObjectId.NewId(); entity.CreatedOn = timeNow; entity.ModifiedOn = timeNow; try { await _memberService.NewMemberInfoAsync(entity).ConfigureAwait(false); } catch (Exception e) { _logger.LogError("LoginModule=regist路由出现后端错误:" + e.Message); } var passwordFormat = EnumHelper.Random(PasswordFormatType.None); var passwordSalt = HashGenerator.Salt(); var password = HashGenerator.Encode(cmd.Password, passwordFormat, passwordSalt); await _memberService.NewMemberAccountAsync(new MemberAccount { Account = cmd.MobilePhone, MemberId = entity.Id, Password = password, PasswordFormat = passwordFormat, PasswordSalt = passwordSalt }); return(Ok(entity)); }
public async Task <CommandResult> UpdateMemberPasswordAsync(string memberId, string newPassword) { Guard.ArgumentNotNullOrEmpty(nameof(memberId), memberId); Guard.ArgumentNotNullOrEmpty(nameof(newPassword), newPassword); using (var conn = CreateConnection()) { var memberAccount = await conn.QueryFirstOrDefaultAsync <MemberAccount>("select * from member_account where member_id=@memberId", new { memberId = new ObjectId(memberId) }).ConfigureAwait(false); if (memberAccount == null) { return(new CommandResult("尚未创建账号")); } memberAccount.Password = HashGenerator.Encode(newPassword, memberAccount.PasswordFormat, memberAccount.PasswordSalt); await conn.UpdateAsync(memberAccount).ConfigureAwait(false); return(CommandResult.SuccessResult); } }
private async Task <Response> InitDebugData() { var timeNow = DateTime.Now; var entity = new MemberInfo { Id = ObjectId.NewId(), Realname = "崔朝辉", Sex = SexType.Unknown, Telephone = "16653555299", MobilePhone = "16653555299", Type = MemberType.SystemAdministrator, Email = "*****@*****.**", IdCard = "370000000000000000", CreatedOn = timeNow, ModifiedOn = timeNow }; try { await _memberService.NewMemberInfoAsync(entity).ConfigureAwait(false); } catch (Exception e) { _logger.LogError("LoginModule=regist路由出现后端错误:" + e.Message); } var passwordFormat = EnumHelper.Random(PasswordFormatType.None); var passwordSalt = HashGenerator.Salt(); var password = HashGenerator.Encode("123456", passwordFormat, passwordSalt); await _memberService.NewMemberAccountAsync(new MemberAccount { Account = "allycs", MemberId = entity.Id, Password = password, PasswordFormat = passwordFormat, PasswordSalt = passwordSalt }); return(Ok(entity)); }