/// <summary> /// /// </summary> /// <param name="account">账户名</param> /// <param name="password">密码</param> /// <param name="inviteAccountId">邀请者账号</param> /// <param name="appleId">应用id</param> /// <param name="referer">来源地址</param> public Users(string account, string password, string inviteAccountId = "", string appleId = "", string referer = "") : this() { this.Account = account; this.SecretKey = Math.Abs($"{this.Id}_{RegisterTime.GetTimeSpan(DateTimeKind.Utc)}".GetHashCode()) .ToString(); this.Password = SecurityCommon.Sha256($"{password}_{SecretKey}"); this.Name = "匿名账户" + DateTime.Now.GetTimeSpan(); this.UserSources = new UserSources(inviteAccountId, appleId, referer); this.AddDomainEvent(new RegisterUserEvent(this.Account, this.Id, inviteAccountId, appleId, referer)); }
/// <summary> /// 根据账户密码得到用户信息 /// </summary> /// <param name="request"></param> /// <param name="context"></param> /// <returns></returns> public override async Task <GetUserReply> GetAccount(GetUserRequest request, ServerCallContext context) { var user = await _userQuery.GetQueryable().FirstOrDefaultAsync(x => x.Account == request.Account); if (user == null) { throw new BusinessException <string>("用户不存在", ErrCode.NoFind.Code); } if (user.Password != SecurityCommon.Sha256($"{request.Password}_{user.SecretKey}")) { throw new BusinessException <string>("账户密码错误", ErrCode.Error.Code); } return(await Task.FromResult(new GetUserReply() { Id = user.Id, Account = user.Account, Avatar = user.Avatar ?? "", Name = user.Name, Registertime = user.RegisterTime.FormatDate(FormatDateType.One) })); }
/// <summary> /// Sha256 /// </summary> /// <param name="bytes"></param> /// <param name="isUpper">是否转大写</param> /// <returns></returns> public static string Sha256(this byte[] bytes, bool isUpper = true) { return(SecurityCommon.Sha256(bytes, isUpper)); }
/// <summary> /// Sha256 /// </summary> /// <param name="stream"></param> /// <param name="isUpper">是否转大写</param> /// <returns></returns> public static string Sha256(this Stream stream, bool isUpper = true) { return(SecurityCommon.Sha256(stream, isUpper)); }