public async Task PutAsync(string key, object value) { if (value == null) { await DeleteAsync(key); return; } var stringBuilder = new StringBuilder(); using (var writer = new StringWriter(stringBuilder)) { var stringValue = value as string; if (stringValue != null) { writer.Write(stringValue); } else { HealthVaultClient.Serializer.Serialize(writer, value, null); } } string stringContent = stringBuilder.ToString(); Encrypted encrypted = m_cryptographer.Encrypt(m_encryptionKey, stringContent); await m_inner.PutAsync(key, encrypted); }
public void SetValue <T>(string key, T value, float expireDurationInDays, bool httpOnly) { var converter = TypeDescriptor.GetConverter(typeof(T)); string cookieValue = string.Empty; try { cookieValue = converter.ConvertToString(value); } catch (NotSupportedException) { if (converter.CanConvertTo(typeof(string))) { cookieValue = (string)converter.ConvertTo(value, typeof(string)); } } if (!string.IsNullOrWhiteSpace(cookieValue)) { var cookie = new HttpCookie(key, _cryptographer.Encrypt(cookieValue)) { Expires = DateTime.Now.AddDays(expireDurationInDays), HttpOnly = httpOnly }; HttpContext.Current.Response.Cookies.Add(cookie); } }
public async Task <long> AddUser(UserRequestDto requestDto) { var user = await _unitOfWork.FindAsyncByPredicateWithIncludeProperty <UserEntity>(x => x.UserName == requestDto.UserName); if (user.Count > 0) { throw new ConflictException($"{requestDto.UserName} user name already exists"); } var userRoles = new List <UserRoleEntity>() { new UserRoleEntity() { RoleId = 2 } }; var userEntity = new UserEntity(); userEntity.UserName = requestDto.UserName; userEntity.FullName = requestDto.FullName; userEntity.UserRoles = userRoles; userEntity.Password = _cryptographer.Encrypt(requestDto.Password); _unitOfWork.Add <UserEntity>(userEntity); await _unitOfWork.SaveChanges(); return(userEntity.Id); }
public void Validate(string username, string password) { var user = _userRepository.Get(username); if (user == null || user.Password != _cryptographer.Encrypt(password)) { throw new AuthenticationFailedException(); } }
public void SetPoints(IDbDataParameter par, Point[] points) { int intCount = points.Length * 2; int byteCount = intCount * 4; if (byteBuf.Length < byteCount) { throw new Exception("Buffer limit exceeded: " + byteCount.ToString()); } PointsToIntBuf(points); if (cryptographer != null) { cryptographer.Encrypt(intBuf, intCount); } Buffer.BlockCopy(intBuf, 0, byteBuf, 0, byteCount); par.Value = byteBuf; par.Size = byteCount; }
public async Task <IActionResult> Login(LoginRequestDto request) { var encryptedPassword = _cryptographer.Encrypt(request.Password); request.Password = encryptedPassword; var resultData = await _authenticationService.Login(request); if (!resultData.IsSuccessfulLogin) { var responseErrorModel = new ResponseErrorModel(400, "Incorrect Username or Password"); return(BadRequest(responseErrorModel)); } var token = BuildToken(resultData); return(Ok(token)); }
public void Handle(CreateUserCommand command) { var user = new User(); user.Login = command.Login; user.Password = _cryptographer.Encrypt(command.Password); var contact = new Contact(); contact.Email = command.Email; contact.Id = Guid.NewGuid(); contact.MobilePhone = command.MobilePhone?.Replace(" ", "").Replace("+", ""); contact.Name = command.Name; contact.Phone = command.Phone?.Replace(" ", "").Replace("+", ""); user.Contact = contact; _contactRepository.Add(contact); _userRepository.Add(user); }
/// <summary> /// Шифрование поля email объекта User /// </summary> /// <param name="user"></param> /// <returns></returns> private User EncryptEmail(User user) { user.email = _crypto.Encrypt(user.email); return(user); }
public void Handle(ChangeUserPasswordCommand command) { var user = _currentUserRetriever.Get(); user.Password = _cryptographer.Encrypt(command.Password); }
/// <summary> /// /// </summary> /// <param name="algorithm"></param> /// <param name="plainConnectString"></param> /// <returns></returns> public static string Encrypt(CryptoAlgorithm algorithm, string plainConnectString) { ICryptographer cryptographer = GetCryptographer(algorithm); return(cryptographer.Encrypt(plainConnectString)); }