public async Task <IActionResult> Modified(string idOrCode, ModifiedInfoUserModel user) { if (string.IsNullOrEmpty(idOrCode) || string.IsNullOrWhiteSpace(idOrCode)) { return(BadRequest()); } try { var userEntity = user.Mapping <User, ModifiedInfoUserModel, UserProfile>(_factory); userEntity.Code = idOrCode; userEntity.Password = EncryptService.Encrypt(user.Password); var data = await _userService.UpdateAsync(userEntity); return(Json(data)); } catch (ExceptionError e) { if (e.Error.ErrorCode.Equals((int)ErrorCodeEnum.FailData)) { Log.Error(e.Error.Data); throw; } else { return(NotFound()); } } }
private byte[] Encrypt(byte[] source) { if (ConfigurationManager.AppSettings[EncryptWidgetTemplate] == "true") { return(EncryptService.Encrypt(source)); } return(source); }
private byte[] Encrypt(byte[] source) { if (Easy.Builder.Configuration[EncryptWidgetTemplate] == "true") { return(EncryptService.Encrypt(source)); } return(source); }
public void TestEncryptText() { var encryptService = new EncryptService(); var decryptedText = File.ReadAllText(@"../../../TestFiles/Decrypted.txt"); var encryptedText = encryptService.Encrypt("скорпион", decryptedText); Assert.AreEqual(encryptedText, File.ReadAllText(@"../../../TestFiles/Encrypted.txt")); }
public void Encrypt_Fail() { IEncryptService encryptService = new EncryptService(); var result = encryptService.Encrypt("test"); var dec = encryptService.Decrypt("WrongPassword", result); Assert.Equal("Password incorrect", dec); }
public void Encrypt_Success() { IEncryptService encryptService = new EncryptService(); var result = encryptService.Encrypt("test"); var dec = encryptService.Decrypt("test", result); Assert.Equal("Password correct", dec); }
public async Task <ActionResult <User> > Insert(UserModel user) { var userEntity = user.Mapping <User, UserModel, UserProfile>(_factory); userEntity.Password = EncryptService.Encrypt("Password"); var data = await _userService.AddAsync(userEntity); return(Json(data)); }
public void Encrypt_Text_ShouldNotReturnSameText() { Account account = new Account() { Password = "******", Username = "******" }; string encryptedText = EncryptService.Encrypt(account.Username); Assert.AreNotEqual(account.Username, encryptedText); }
private async Task <UserInfoModel> LoginAsync(User user, string password, CancellationToken cancellationToken = default) { if (user != null) { string passEncrypt = EncryptService.Encrypt(password); if (user.Password.Equals(passEncrypt)) { if (user.Status != StatusEnum.Inactive && (user.LoginFailedNumber == null || (user.LoginFailedNumber != null && user.LoginFailedNumber.Value < _maxLogin))) { user.LoginFailedNumber = 0; var model = UserInfoModel.Instance; model.Fullname = user.FullName; model.Id = user.Id; model.UserType = user.UserTypeStr; model.Username = user.Username; model.PasswordLastUpdate = user.PasswordLastUdt; model = await CheckExpiredPass(model); await _userRepo.UpdateAsync(user); // _logService.Synchronization(user.Username); return(model); } else { throw new ExceptionError(ErrorCodeEnum.UserInactive); } } else { if (user.LoginFailedNumber != null && user.LoginFailedNumber.Value >= (_maxLogin - 1) && user.Status != StatusEnum.Inactive) { user.Status = StatusEnum.Inactive; user.LoginFailedNumber = 0; await _userRepo.UpdateAsync(user); throw new ExceptionError(ErrorCodeEnum.LoginFailed3Time); } if (user.Status == StatusEnum.Inactive) { throw new ExceptionError(ErrorCodeEnum.UserInactive); } user.LoginFailedNumber = user.LoginFailedNumber == null ? 1 : user.LoginFailedNumber.Value + 1; await _userRepo.UpdateAsync(user); throw new ExceptionError(ErrorCodeEnum.LoginFailed); } } else { Log.Information("User does not existed!", ErrorCodeEnum.IncorrectUser); throw new ExceptionError(ErrorCodeEnum.IncorrectUser); } }
private UserOutput Login(User user, string password) { if (user != null) { string passEncrypt = EncryptService.Encrypt(password); if (user.Password.Equals(passEncrypt)) { if (user.Status != StatusEnum.Inactive && (user.LoginFailedNumber == null || (user.LoginFailedNumber != null && user.LoginFailedNumber.Value < _maxLogin))) { user.LoginFailedNumber = 0; var userOutput = new UserOutput(user); CheckExpiredPass(ref userOutput); _unitOfWork.Update(user); _unitOfWork.Commit(); _logService.Synchronization(user.Username); return(userOutput); } else { throw new DefinedException(ErrorCodeEnum.UserInactive); } } else { if (user.LoginFailedNumber != null && user.LoginFailedNumber.Value >= (_maxLogin - 1) && user.Status != StatusEnum.Inactive) { user.Status = StatusEnum.Inactive; user.LoginFailedNumber = 0; _unitOfWork.Update(user); _unitOfWork.Commit(); throw new DefinedException(ErrorCodeEnum.LoginFailed3Time); } if (user.Status == StatusEnum.Inactive) { throw new DefinedException(ErrorCodeEnum.UserInactive); } user.LoginFailedNumber = user.LoginFailedNumber == null ? 1 : user.LoginFailedNumber.Value + 1; _unitOfWork.Update(user); _unitOfWork.Commit(); throw new DefinedException(ErrorCodeEnum.LoginFailed); } } else { Log.Information("User does not existed!", ErrorCodeEnum.IncorrectUser); throw new DefinedException(ErrorCodeEnum.IncorrectUser); } }
public void Test1(string url, string result) { var Key = "Use 32 Characters For Encryption"; var moqSiteSettings = new Mock <IOptionsSnapshot <SiteSettings> >(); var siteSettings = new SiteSettings() { EncryptionSettings = new EncryptionSettings() { Key = Key } }; moqSiteSettings.Setup(x => x.Value).Returns(siteSettings); var service = new EncryptService(moqSiteSettings.Object); var resultService = service.Encrypt(url); Assert.Equal(resultService, result); }
private string GeneratePassword() { int lowercase = 4; int uppercase = 3; int numerics = 2; string lowers = "abcdefghijklmnopqrstuvwxyz"; string uppers = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; string number = "0123456789"; Random random = new Random(); string generated = "!"; for (int i = 1; i <= lowercase; i++) { generated = generated.Insert( random.Next(generated.Length), lowers[random.Next(lowers.Length - 1)].ToString() ); } for (int i = 1; i <= uppercase; i++) { generated = generated.Insert( random.Next(generated.Length), uppers[random.Next(uppers.Length - 1)].ToString() ); } for (int i = 1; i <= numerics; i++) { generated = generated.Insert( random.Next(generated.Length), number[random.Next(number.Length - 1)].ToString() ); } return(EncryptService.Encrypt(generated)); }
private async void Save() { if (string.IsNullOrEmpty(Name) || string.IsNullOrEmpty(LastName) || string.IsNullOrEmpty(Email) || string.IsNullOrEmpty(Gender) || string.IsNullOrEmpty(Document)) { await dialogService.ShowMessage("Error", "Completa todos los espacios antes de comenzar"); return; } if (Password.Equals(RepeatPassword)) { await dialogService.ShowMessage("Ups", "Las contaseñas no coinciden"); return; } if (!CrossConnectivity.Current.IsConnected) { await dialogService.ShowMessage("Ups", "Parece que no tienes conexión a internet"); } var passwordEncrypt = encryptService.Encrypt(Password); string uid = await auth.CreateNewUser(Email, passwordEncrypt); InsertFireBase service = new InsertFireBase(); if (uid != "") { await service.AddClient(uid, Name, Role, LastName, Mobile, Address, Birth, Email, Document, Gender, Verification, true); await navigationService.Navigate("Principal"); } else { await dialogService.ShowMessage("Error", "Hubo un error en el camino, intentalo nuevamente"); } }
public void ChangePassword(DataInput <ChangePasswordInput> requestDto) { User user = GetUserContact(requestDto.CurrentUser); if (user != null) { string passEncrypt = EncryptService.Encrypt(requestDto.Dto.CurrentPassword); if (user.Password.Equals(passEncrypt)) { if (!requestDto.Dto.NewPassword.CheckPassFormat()) { Log.Information("Password {Password} wrong format!", requestDto.Dto.NewPassword); throw new DefinedException(ErrorCodeEnum.PasswordWrongFormat); } user.Password = passEncrypt; user.PasswordLastUdt = DateTime.Now; user.LastUpdatedBy = requestDto.CurrentUser; user.LastUpdateDate = DateTime.Now; try { _userRepository.Update(user); _unitOfWork.Commit(); } catch (Exception e) { Log.Information(e, "Update Error: " + e.Message); throw new SqlException("Update Error: " + e.Message, e); } } else { Log.Information("Change Password Error: Incorrect Password!"); throw new DefinedException(ErrorCodeEnum.IncorrectPassword); } } }
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously public async Task Seed() { var change = false; if (!_context.Users.Any(x => x.UserType == UserTypeEnum.SuperAdmin)) { List <User> listUser = new List <User>() { new User() { Code = EnumIDGenerate.SuperAdmin.GenerateCode(100001), UserType = UserTypeEnum.SuperAdmin, Username = _configuration["SuperAdmin:Username"], FullName = _configuration["SuperAdmin:Fullname"], Phone = _configuration["SuperAdmin:Default"], Email = _configuration["SuperAdmin:Email"], Address = _configuration["SuperAdmin:Default"], Status = StatusEnum.Active, Password = EncryptService.Encrypt(_configuration["SuperAdmin:Password"]), CreatedBy = _configuration["Auto:Create"] }, new User() { Code = EnumIDGenerate.SuperAdmin.GenerateCode(100002), UserType = UserTypeEnum.SuperAdmin, Username = "******", FullName = "SuperAdmin", Phone = "NA", Email = _configuration["SuperAdmin:Email"], Address = _configuration["SuperAdmin:Default"], Status = StatusEnum.Active, Password = EncryptService.Encrypt("string"), CreatedBy = _configuration["Auto:Create"] }, }; _context.Users.AddRange(listUser); change = true; } IList <SystemConfiguration> defaultConfig = new List <SystemConfiguration>(); defaultConfig.Add(item: new SystemConfiguration { Key = SystemConfigEnum.ArchiveJobHistory, Value = "2", Unit = Unit.months }); defaultConfig.Add(item: new SystemConfiguration { Key = SystemConfigEnum.ArchiveLogData, Value = "2", Unit = Unit.weeks }); defaultConfig.Add(item: new SystemConfiguration { Key = SystemConfigEnum.WebPassExpDate, Value = "30", Unit = Unit.days }); defaultConfig.Add(item: new SystemConfiguration { Key = SystemConfigEnum.AppPassExpDate, Value = "30", Unit = Unit.minutes }); defaultConfig.Add(item: new SystemConfiguration { Key = SystemConfigEnum.WebSessExpDate, Value = "45", Unit = Unit.minutes }); defaultConfig.Add(item: new SystemConfiguration { Key = SystemConfigEnum.AppSessExpDate, Value = "45", Unit = Unit.minutes }); //defaultConfig.Add(item: new SystemConfiguration { Key = SystemConfigEnum.OpenEAM, Value = "false", Unit = Unit.boolean }); foreach (var item in defaultConfig) { if (!_context.SystemConfigurations.Any(x => x.Key == item.Key)) { _context.SystemConfigurations.Add(new SystemConfiguration { CreatedBy = _configuration["Auto:Create"], Value = item.Value, Unit = item.Unit, Key = item.Key, CreatedDate = Clock.Now }); change = true; } } if (change) { _context.SaveChanges(); } }
public async void Login() { try { if (string.IsNullOrEmpty(_userName) || string.IsNullOrEmpty(_password)) { _notificationsService.ShowAlert(UINotifications.General_AttentionCaption, UINotifications.AuthorizationPage_WrongPasswordOrUserName); return; } StartBusiness(); var authorizationService = _authorizationFactory.GetAuthorizationService(new CatalogModel { Id = CatalogId, Type = CatalogType }); var authorizationString = await authorizationService.Authorize(_userName, _password, Path); if (!string.IsNullOrEmpty(authorizationString)) { var catalog = _catalogRepository.Get(CatalogId); catalog.AuthorizationString = EncryptService.Encrypt(authorizationString); _catalogRepository.Save(catalog); if (!string.IsNullOrEmpty(CatalogBookItemKey)) { var catalogBookItemModel = TransientStorage.Get <CatalogBookItemModel>(CatalogBookItemKey); _navigationService .UriFor <BookInfoPageViewModel>() .WithParam(vm => vm.Title, catalogBookItemModel.Title.ToUpper()) .WithParam(vm => vm.Description, catalogBookItemModel.Description) .WithParam(vm => vm.ImageUrl, catalogBookItemModel.ImageUrl) .WithParam(vm => vm.CatalogId, CatalogId) .WithParam(vm => vm.CatalogBookItemKey, TransientStorage.Put(catalogBookItemModel)) .Navigate(); } else { _navigationService.UriFor <CatalogPageViewModel>() .WithParam(vm => vm.CatalogId, catalog.Id) .WithParam(vm => vm.DisplayName, _catalogController.GetCatalogTitle(catalog).ToUpper()) .WithParam(vm => vm.IsSearchEnabled, !string.IsNullOrEmpty(catalog.SearchUrl) || catalog.Type == CatalogType.SDCard || catalog.Type == CatalogType.SkyDrive) .WithParam(vm => vm.CanRefresh, catalog.Type != CatalogType.SDCard) .Navigate(); } } else { StopBusiness(); _notificationsService.ShowAlert(UINotifications.General_AttentionCaption, UINotifications.AuthorizationPage_WrongPasswordOrUserName); } } catch (Exception exception) { _errorHandler.Handle(exception); } finally { StopBusiness(); } }
private static Account EncryptAccount(Account account) { account.Username = EncryptService.Encrypt(account.Username); account.Password = EncryptService.Encrypt(account.Password); return(account); }
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously public async Task Seed() { #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously var change = false; if (!_context.Users.Any(x => x.UserType == UserTypeEnum.SuperAdmin)) { List <User> listUser = new List <User>() { new User() { Code = EnumIDGenerate.SuperAdmin.GenerateCode(100001), UserType = UserTypeEnum.SuperAdmin, Username = _configuration["SuperAdmin:Username"], FullName = _configuration["SuperAdmin:Fullname"], Phone = _configuration["SuperAdmin:Default"], Email = _configuration["SuperAdmin:Email"], Address = _configuration["SuperAdmin:Default"], Users = "All", Status = StatusEnum.Active, Password = EncryptService.Encrypt(_configuration["SuperAdmin:Password"]), CreatedBy = _configuration["Auto:Create"] }, new User() { Code = EnumIDGenerate.SuperAdmin.GenerateCode(100002), UserType = UserTypeEnum.SuperAdmin, Username = "******", FullName = "SuperAdmin", Phone = "NA", Email = _configuration["SuperAdmin:Email"], Address = _configuration["SuperAdmin:Default"], Users = "All", Status = StatusEnum.Active, Password = EncryptService.Encrypt("string"), CreatedBy = _configuration["Auto:Create"] }, }; _context.Users.AddRange(listUser); change = true; } IList <SystemConfiguration> defaultConfig = new List <SystemConfiguration>(); defaultConfig.Add(item: new SystemConfiguration { Key = SystemConfigEnum.ArchiveJobHistory, Value = "2", Unit = Unit.months }); defaultConfig.Add(item: new SystemConfiguration { Key = SystemConfigEnum.ArchiveLogData, Value = "2", Unit = Unit.weeks }); defaultConfig.Add(item: new SystemConfiguration { Key = SystemConfigEnum.OpenEAM, Value = "false", Unit = Unit.boolean }); defaultConfig.Add(item: new SystemConfiguration { Key = SystemConfigEnum.WebPassExpDate, Value = "30", Unit = Unit.days }); defaultConfig.Add(item: new SystemConfiguration { Key = SystemConfigEnum.AppPassExpDate, Value = "30", Unit = Unit.minutes }); defaultConfig.Add(item: new SystemConfiguration { Key = SystemConfigEnum.WebSessExpDate, Value = "1", Unit = Unit.hour }); defaultConfig.Add(item: new SystemConfiguration { Key = SystemConfigEnum.AppSessExpDate, Value = "1", Unit = Unit.hour }); foreach (var item in defaultConfig) { if (!_context.SystemConfigurations.Any(x => x.Key == item.Key)) { _context.SystemConfigurations.Add(new SystemConfiguration { CreatedBy = _configuration["Auto:Create"], Value = item.Value, Unit = item.Unit, Key = item.Key, CreatedDate = Clock.Now }); change = true; } } if (_context.Countries.Count() == 0) { List <Country> listCountry = new List <Country>() { new Country() { CountryId = "AS", CountryName = "Samoa (American)", CurrencyName = "USD", Region = "APAC", CurrencySig = "$" }, new Country() { CountryId = "AU", CountryName = "Australia", CurrencyName = "AUD", Region = "APAC", CurrencySig = "$" }, new Country() { CountryId = "BN", CountryName = "Brunei", CurrencyName = "BND", Region = "APAC", CurrencySig = "B$" }, new Country() { CountryId = "BT", CountryName = "Bhutan", CurrencyName = "BTN", Region = "APAC", CurrencySig = "Nu" }, new Country() { CountryId = "HK", CountryName = "Hong Kong", CurrencyName = "HKD", Region = "APAC", CurrencySig = "₣" }, new Country() { CountryId = "ID", CountryName = "Indonesia", CurrencyName = "IDR", Region = "APAC", CurrencySig = "Rp" }, new Country() { CountryId = "JP", CountryName = "Japan", CurrencyName = "JPY", Region = "APAC", CurrencySig = "¥" }, new Country() { CountryId = "KH", CountryName = "Kampuchea", CurrencyName = "KHR", Region = "APAC", CurrencySig = "CR" }, new Country() { CountryId = "KR", CountryName = "Korea (South)", CurrencyName = "KRW", Region = "APAC", CurrencySig = "₩" }, new Country() { CountryId = "LA", CountryName = "Laos", CurrencyName = "LAK", Region = "APAC", CurrencySig = "₭" }, new Country() { CountryId = "MM", CountryName = "Myanmar", CurrencyName = "MMK", Region = "APAC", CurrencySig = "K" }, new Country() { CountryId = "MN", CountryName = "Mongolia", CurrencyName = "MNT", Region = "APAC", CurrencySig = "₮" }, new Country() { CountryId = "MO", CountryName = "Macao", CurrencyName = "MOP", Region = "APAC", CurrencySig = "MOP$" }, new Country() { CountryId = "MY", CountryName = "Malaysia", CurrencyName = "MYR", Region = "APAC", CurrencySig = "RM" }, new Country() { CountryId = "NC", CountryName = "New Caledonia", CurrencyName = "CFP", Region = "APAC", CurrencySig = "₣" }, new Country() { CountryId = "NR", CountryName = "Nauru", CurrencyName = "AUD", Region = "APAC", CurrencySig = "$" }, new Country() { CountryId = "NU", CountryName = "Niue", CurrencyName = "NZD", Region = "APAC", CurrencySig = "$" }, new Country() { CountryId = "NZ", CountryName = "New Zealand", CurrencyName = "NZD", Region = "APAC", CurrencySig = "$" }, new Country() { CountryId = "P2", CountryName = "French Polynesia & New Caledonia", CurrencyName = "CFP", Region = "APAC", CurrencySig = "₣" }, new Country() { CountryId = "PF", CountryName = "Polynesia (French)", CurrencyName = "CFP", Region = "APAC", CurrencySig = "₣" }, new Country() { CountryId = "PH", CountryName = "Philippines", CurrencyName = "PHP", Region = "APAC", CurrencySig = "₱" }, new Country() { CountryId = "PN", CountryName = "Pitcairn", CurrencyName = "NZD", Region = "APAC", CurrencySig = "$" }, new Country() { CountryId = "PW", CountryName = "Palau", CurrencyName = "USD", Region = "APAC", CurrencySig = "$" }, new Country() { CountryId = "SG", CountryName = "Singapore", CurrencyName = "SGD", Region = "APAC", CurrencySig = "$" }, new Country() { CountryId = "TH", CountryName = "Thai Lan", CurrencyName = "Baht", Region = "APAC", CurrencySig = "" }, new Country() { CountryId = "VN", CountryName = "Viet Nam", CurrencyName = "VND", Region = "APAC", CurrencySig = "₫" }, }; _context.Countries.AddRange(listCountry); change = true; } if (_context.Groups.Count() == 0) { List <Group> listGroup = new List <Group>() { new Group() { GroupCode = "GG", GroupName = "Group 1", CreatedBy = _configuration["Auto:Create"] }, new Group() { GroupCode = "VG", GroupName = "Group 2", CreatedBy = _configuration["Auto:Create"] }, new Group() { GroupCode = "GD", GroupName = "Group 3", CreatedBy = _configuration["Auto:Create"] }, new Group() { GroupCode = "MD", GroupName = "Group 4", CreatedBy = _configuration["Auto:Create"] }, new Group() { GroupCode = "BG", GroupName = "Group 5", CreatedBy = _configuration["Auto:Create"] }, new Group() { GroupCode = "BA", GroupName = "Group 6", CreatedBy = _configuration["Auto:Create"] }, new Group() { GroupCode = "DF", GroupName = "Group 7", CreatedBy = _configuration["Auto:Create"] }, }; _context.Groups.AddRange(listGroup); change = true; } if (change) { _context.SaveChanges(); } }
public async Task Seed() { var change = false; if (!_context.Users.Any(x => x.UserType == UserTypeEnum.SuperAdmin)) { List <User> listUser = new List <User>() { new User() { Code = string.Join("", Guid.NewGuid().ToString().Split("-")), UserType = UserTypeEnum.SuperAdmin, Username = _configuration["SuperAdmin:Username"], FullName = _configuration["SuperAdmin:Fullname"], Phone = _configuration["SuperAdmin:Default"], Email = _configuration["SuperAdmin:Email"], Address = _configuration["SuperAdmin:Default"], Status = StatusEnum.Active, Password = EncryptService.Encrypt(_configuration["SuperAdmin:Password"]), CreatedBy = _configuration["Auto:Create"] }, }; var entities = _context.Set <User>(); entities.AddRange(listUser); change = true; } if (change) { await _context.SaveChangesAsync(); } return; }
private async void Login() { if (string.IsNullOrEmpty(UserName) && string.IsNullOrEmpty(Password)) { IsVisible = true; Message = "Debes ingresar numero de celular y contraseña"; ColorEntryPhone = "Yellow"; ColorEntryPassword = "******"; return; } if (string.IsNullOrEmpty(UserName)) { ColorEntryPassword = "******"; IsVisible = true; Message = "Debes ingresar el numero de celular"; ColorEntryPhone = "Yellow"; return; } if (string.IsNullOrEmpty(Password)) { ColorEntryPhone = "Black"; IsVisible = true; Message = "Debes ingresar la contraseña"; ColorEntryPassword = "******"; return; } ColorEntryPhone = "Black"; ColorEntryPassword = "******"; IsVisible = false; IsRunning = true; IsEnabled = false; var connection = await apiService.CheckConnection(); if (!connection.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage("Error", connection.Message); return; } var passwordEncrypt = encryptService.Encrypt(Password); string Token = await auth.LoginWithEmailPassword(UserName, passwordEncrypt); if (Token != "") { await navigationService.Navigate("Principal"); IsRunning = false; IsEnabled = true; } else { await dialogService.ShowMessage("Error", "Correo electronico o contraseña incorrectos"); IsRunning = false; IsEnabled = true; } //var passwordEncrypt = encryptService.Encrypt(Password); }