private async Task CacheQuery(TblIdentityCredential result, string token) { // Add token to caching server var identitySession = _cachingService.IdentitySessions.FirstOrDefault(i => i.Guid == Guid.Parse(result.IdentityInfo.Uuid)); _cachingService.IdentitySessions.Remove(identitySession); _cachingService.IdentitySessions.Add(new IdentitySessionBO() { Token = token, LogonDateTime = DateTime.Now, SessionState = SessionState.Active, MaxSessionTimeSpan = TimeSpan.FromMinutes(30) }); }
private bool GetCredential(ChangePasswordCmd request, CancellationToken cancellationToken, out TblIdentityCredential entity, out CmdResponse <ChangePasswordCmd> handle) { entity = _dataLayer.TblIdentityCredentials .Where(i => i.Guid == $"{request.CredentialGuid}" || i.UserName == request.UserName) .FirstOrDefault(); if (entity != null) { handle = new(); return(false); } var entityList1 = _dataLayer.TblIdentityContacts .Include(i => i.UserCredential) .Where(i => i.Value == request.PhoneNumber.ValidatePhoneNumber(false) && i.UcentitiesId == (long?)GenericContactType.Phone) .Select(i => i.UserCredential) .ToList(); if (entityList1.Count > 1) { { handle = new() { Message = $"Identity with data [PhoneNumber: {request.PhoneNumber}] exists on multiple identities and is therefore ambiguous", HttpStatusCode = HttpStatusCode.Conflict }; return(true); } } if (entityList1.Any()) { entity = entityList1.First(); } if (entity != null) { handle = new(); return(false); } request.Email.ValidateEmailAddress(); var entityList2 = _dataLayer.TblIdentityContacts .Include(i => i.UserCredential) .Where(i => i.Value == request.Email && i.UcentitiesId == (long?)GenericContactType.Email) .Select(i => i.UserCredential) .ToList(); if (entityList2.Count > 1) { { handle = new() { Message = $"Identity with data [Email: {request.Email};] exists on multiple identities and is therefore ambiguous", HttpStatusCode = HttpStatusCode.Conflict }; return(true); } } if (entityList2.Any()) { entity = entityList2.First(); } if (entity != null) { handle = new(); return(false); } handle = new() { Message = $"Identity with data [GUID: {request.CredentialGuid}; UserName: {request.UserName}; Email: {request.Email}; PhoneNumber: {request.PhoneNumber}] does not exist", HttpStatusCode = HttpStatusCode.NotFound }; return(true); } }
private async Task <List <TblIdentityRole> > GetRoleList(CancellationToken cancellationToken, TblIdentityCredential credential, Guid cuid) { var roleList = await _dataLayer.TblIdentityRoles .AsNoTracking() .Where(i => i.UserCredId == credential.Id) .ToListAsync(cancellationToken: cancellationToken); if (roleList == null) { _recordsService.NewAuthorizationLog(AuthenticationState.InvalidUser, cuid); return(roleList); } return(roleList); }
private async Task <TblIdentityCredential> ValidatePassword(AuthenticateIdentityQuery request, AuthorizeBy authorizeBy, TblIdentityCredential credential, CancellationToken cancellationToken) { SHA512 shaM = new SHA512Managed(); var passwordByte = Encoding.ASCII.GetBytes(request.Password); var hashPasswordByte = shaM.ComputeHash(passwordByte); if (authorizeBy == AuthorizeBy.Token) { return(credential); } credential = await _dataLayer.TblIdentityCredentials .Include(i => i.IdentityInfo) .FirstOrDefaultAsync(i => i.Id == credential.Id & i.PasswordByte == hashPasswordByte, cancellationToken: cancellationToken); return(credential); }
private async Task <TblIdentityCredential> ValidatePassword(AuthenticateCredentialQuery request, AuthorizeBy authorizeBy, TblIdentityCredential credential, CancellationToken cancellationToken) { if (authorizeBy == AuthorizeBy.Token) { return(credential); } var hashPassword = Encoding.ASCII.GetString(credential.PasswordByte); return(!BCrypt.Net.BCrypt.Verify(request.Password, hashPassword) ? null : credential); }