public static string EncryptMySecret() { //this is your 64-bit key string string myKeyString = AESEncryptor.CreateNewKey(); using (var manager = new EncryptionManager(myKeyString)) { //This is your initializor, or public key string iv = AESEncryptor.CreateInitializor(); //This is how you encrypt with your specified key and iv encryptedSecretInfo = manager.Encrypt(secretInfo, iv); } //you can also encrypt with private keys of int a, b and c using (var manager = new EncryptionManager(100, 50, 10)) { //This is your initializor, or public key string iv = manager.CreateInitializor(); //This is your second public key, used with a, b, and c to compute the private key long ticks = DateTime.Now.Ticks; //This is how you encrypt with your specified key and iv encryptedSecretInfo = manager.Encrypt(secretInfo, iv, ticks); } return(encryptedSecretInfo); }
private void btn_Save_Click(object sender, EventArgs e) { #region SaveSqlConnectionStringToXml DataTable dtSetting = new DataTable("dtSetting"); dtSetting.Columns.Add("Server"); dtSetting.Columns.Add("User"); dtSetting.Columns.Add("Password"); dtSetting.Columns.Add("IsWindowsAuth"); if (!File.Exists("dtSetting.xsd")) { dtSetting.WriteXmlSchema("dtSetting.xsd"); } DataRow dr = dtSetting.NewRow(); dr["Server"] = tb_Server.Text; dr["User"] = tb_DbUser.Text; dr["Password"] = EncryptionManager.Encrypt(tb_DbPass.Text); dr["IsWindowsAuth"] = radioGroup1.SelectedIndex.ToString(); dtSetting.Rows.Add(dr); dtSetting.WriteXml("dtSetting.xml"); #endregion connectSQLSERVER(tb_Server.Text, tb_DbUser.Text, tb_DbPass.Text, radioGroup1.SelectedIndex); Close(); }
public async Task <bool> Register(string name, string phone, string email, string pass, Gender gender, Role role) { try { var old = await _manager.Users.SingleOrDefault(x => x.Phone == phone || x.Email == email); if (old != null) { return(false); } else { _manager.Users.Add(new User { CreateDate = DateTime.Now, Email = email, Gender = gender, IsActive = true, Password = EncryptionManager.Encrypt(pass), Name = name, Phone = phone, Role = role, Serial = Guid.NewGuid().ToString(), }); } } catch (Exception e) { } return(await _manager.Complete()); }
public async Task <bool> ConfiremPassword(User us, string pass) { //Encrypting the password first. pass = EncryptionManager.Encrypt(pass); var user = await _manager.Users.SingleOrDefault(x => x.Id == us.Id); return((user != null) && user.Password == pass); }
/// <summary> /// Encrypts a string using a password to generate an alphabet character array. /// </summary> /// <param name="text"></param> /// <param name="password"></param> /// <returns></returns> public string Encrypt(string text, string password) { var alphabet = new Alphabet().GenerateAlphabetFromPassword(password); var manager = new EncryptionManager(); return manager.Encrypt(text, alphabet); }
public async Task <bool> NewTransaction(PurchaseVM purchaseVm, string cpass, long userId) { var user = await _manager.Users.GetSingle(userId); if (user != null && user.Password == EncryptionManager.Encrypt(cpass)) { using (var con = new SEDCControle(_manager)) { var result = await con.Purchase(purchaseVm); if (result.State == "0") { List <Power> pws = new List <Power>(); foreach (var x in result.Items) { pws.Add(new Power { Tid = x.Id, amt = x.Amt, kwh = x.Kwh, price = x.Price }); } _manager.SEDCTransaction.Add(new SEDCTransaction { verifyCode = result.VerifyCode, meterNum = result.MeterNum, CreateDate = DateTime.Now, transID = result.TransId, AMT = result.Amt, UserId = userId, Powers = pws, VAT = result.Vat, arrearAMT = result.ArrearAmt, buyTimes = result.BuyTimes, vendQty = result.VendQty, vendAMT = result.VendAmt, transTime = result.TransTime, token = result.Token, tariffCode = result.TariffCode, supplyAMT = result.SupplyAmt, state = result.State, stampTax = result.StampTax, regCode = result.RegCode, refCode = result.RefCode, netAMT = result.NetAmt, invoice = result.Invoice, feeAMT = result.FeeAmt, customerName = result.CustomerName, commAMT = result.CommAmt, code = result.Code, checkCode = result.CheckCode, calcQty = result.CalcQty }); return(await _manager.Complete()); } } } return(false); }
public void ProtectProtects() { EncryptionManager .Encrypt(Arg.Any <string>(), Arg.Any <byte[]>()) .Returns(new EncryptionResult( protectedSecret.InitialisationVector, protectedSecret.ProtectedDocumentKey, protectedSecret.ProtectedSecretValue)); }
public string GetConnectionString() { string conexionString = ""; var prod = EncryptionManager.Decrypt("DnGSNiEDyELYKyAJW5l0025tuH5UdV8KhDpuMov19fi/s1sc6L51juiMAuKYrr/wjoWA5Oped33RVDppqouAUHOiFxu8MTVatm9EKhHmcVuCyi1KxKeFc7ksuNHi5T+SNa7yVysH1lbhMRwWHfRCTYbH/X58OXOVeGRZpabN4fQ5FezNIwsWgdt/CtwRUpXakflSD2K4Knv3VkuaBvL1NAYC6lQtG0P3Ycl2Im8XqeB+uzHxwVSVxvtCrrEwwkl69Bk68driwOPDDUYi86pzKCvCh+s3tpoxPWxZTbf5ymsx/+RUa94dcYsZY+aYxbv+FgTdy8lMSC0GkJuD4Afrm4vvAyFkFDgwhjcO97aaIipOVTB1VyRiht8AE0nRYvPQgj8tHEA5yQ9G9MCv7nkCcy925oX35HNOo9IDepcEfY5JvEnEMPEmc1tctCZp8vvk8/WxKGAgxotgoQrNeHE84PcCpHUY9UV6BiKJe3TBWuwFW2MIAmv3nfewKqeXliX4r5EvgNjzSztAo+wyqHB/7ZdW/qngDdmREKvoCPyVArzUTtBjGEdFmeDs9gP1yEAX"); var encrypt = EncryptionManager.Encrypt(prod); conexionString = prod; return(conexionString); }
public string GetConnectionString() { string conexionString = ""; var prod = EncryptionManager.Decrypt("kPpN+ncRSXeJHLpuqqOSa97k7hobl3V8PblQZmsXuxdhKHnvI1dum+9fRxTSLvPN5IuAWy1+5fQL9TPsLKk++nV/ndwgIJ2dQjQ30I/jIrpvOBtprKpkGunNqIeMG0lagE7GzSKN4bs2I1rfI1cwWj3cQzQvsMIoFjdaojL0zrLaBlQW4O7N+jlQ9FvZeQXepWGqARzMAy8f4j8IzkP8XJiuvw5dvDZdhww0K4QsvXweKcxTt6feooANQsSVc6ktMnKTByVtGrd4XwjC9Q32LF78o3CWe/MLlqQaoimzjDE2SYL7FvMBdVTdZsBZXePTxpKJ9IgVAcr6TeZGoAYSMzBQoLHRXayeV0cuVOy8cunXh5ST2hMQiSlVgxpfWuU0XTMZzK40CEVgIqnXtm8Mpx2I9JwnC/hATVlTbvSQOG7oEvq0YCJrUbbYefxz35BGlEhmSM1u72zhh2HQssQTB4cNanuIt62agyfDaZ+4H2ktUrcjNRcA/c0jgPlFlesDAihv00lsUo4K+K/8fJ39jQ=="); var encrypt = EncryptionManager.Encrypt(prod); conexionString = prod; return(conexionString); }
private void StoreInLocalSettings() { //Module 13 - Securing Windows 8 App Data _settings.Add(Constants.TravelerId, EncryptionManager.Encrypt(this.TravelerId.ToString())); _settings.Add(Constants.FirstName, EncryptionManager.Encrypt(this.FirstName)); _settings.Add(Constants.LastName, EncryptionManager.Encrypt(this.LastName)); _settings.Add(Constants.Passport, EncryptionManager.Encrypt(this.Passport)); _settings.Add(Constants.HomeAddress, EncryptionManager.Encrypt(this.HomeAddress)); _settings.Add(Constants.MobilePhone, EncryptionManager.Encrypt(this.MobilePhone)); _settings.Add(Constants.Email, EncryptionManager.Encrypt(this.Email)); }
public async Task <GenerateTransState> NewTransaction(decimal amount, string toId, long fromAccount, string cpass, bool recharge = false) { try { cpass = EncryptionManager.Encrypt(cpass); var senderUser = await _manager.Users.GetSingle(fromAccount); if (senderUser != null && cpass == senderUser.Password) { if (recharge) { var state = await CreateTransaction(senderUser, senderUser, amount, false); return((state) ? GenerateTransState.Success : GenerateTransState.Error); } else { var toAccount = await _manager.Users.SingleOrDefault(x => x.Serial == toId); if (toAccount == null) { return(GenerateTransState.AccountNotExist); } IEnumerable <InternalTransaction> senderTranses = await _manager.InternalTransactions.Find(x => x.UserId == senderUser.Id); var vm = new AccountVM(senderTranses.ToList()); if (vm.Balance >= amount) { var state = await CreateTransaction(senderUser, toAccount, amount, true); return((state) ? GenerateTransState.Success : GenerateTransState.Error); } else { return(GenerateTransState.AmountIsHi); } //return (vm.Balance >= amount) ? ((await CreateTransaction(senderUser, toAccount, amount, true)) ? GenerateTransState.Success : GenerateTransState.Error) : GenerateTransState.AmountIsHi; } } else { return(GenerateTransState.PasswordIsNotCurrect); } } catch (Exception e) { return(GenerateTransState.Error); } }
public static string GenerateContentAuthenticationResponse(string token) { // should be called on web app RPIdentity rpIdentity = (RPIdentity)HttpContext.Current.User.Identity; string data = EncryptionManager.Encrypt(rpIdentity.GetCookieString()); var uriBuilder = new UriBuilder { Host = WebUrlManager.Host, Scheme = HttpContext.Current.Request.Url.Scheme, Path = "user/authenticate", Query = $"token={token}&data={data}" }; return(uriBuilder.ToString()); }
/// <summary> /// Add new password to the user. /// </summary> /// <param name="user"></param> /// <returns></returns> public async Task <bool> SetPassword(User user) { //check the user first. var isExist = await _manager.Users.SingleOrDefault(x => x.UserName == user.UserName || x.Phone == user.Phone); if (isExist != null) { //set password. isExist.Password = EncryptionManager.Encrypt(user.Password); isExist.SetNewPassword = false; _manager.Users.Update(isExist); } return(await _manager.Complete()); }
public static void Init(string _sKEY = null, string _sIV = null) { sKEY = _sKEY ?? sKEY; sIV = _sIV ?? sIV; string key = PlayerPrefs.GetString(EncryptionManager.GetHashEx(publicKey), ""); if (key != "") { publicKeyStr = EncryptionManager.Decrypt(key); } else { publicKeyStr = Utils.GetRandomString(16) + SystemInfo.deviceUniqueIdentifier; PlayerPrefs.SetString(EncryptionManager.GetHashEx(publicKey), EncryptionManager.Encrypt(publicKeyStr)); } }
public ActionResult ConsultantsRegister(ConsultantsAccount _useraccount, HttpPostedFileBase file1, HttpPostedFileBase file2, String checkboxSelectCombo) { if (!CheckContentOfLoginRegister(_useraccount.UserName, _useraccount.Password, _useraccount.ConfirmPassword, _useraccount.Email, _useraccount.FirstName, _useraccount.LastName)) { TempData["Message"] = "Something went wrong,Try again!"; return(View()); } var collection2 = Context.Database.GetCollection <UserAccount>("Users"); usersQuery = Query <UserAccount> .Where(s => s.UserName == _useraccount.UserName); var model1 = collection2.FindOne(usersQuery); var collection = Context.Database.GetCollection <ConsultantsAccount>("Consultants"); consulQuery = Query <ConsultantsAccount> .Where(s => s.UserName == _useraccount.UserName); var model = collection.FindOne(consulQuery); if (model == null && model1 == null) { string checkbox = Request.Form["check"]; if (checkbox == "true") { _useraccount.CheckBox = 1; } if (file1 != null) { _useraccount.Documents1 = InsertFileToDB(file1); } if (file2 != null) { _useraccount.Documents2 = InsertFileToDB(file2); } string encriptedPassword = EncryptionManager.Encrypt(_useraccount.Password, c_passwordKey); _useraccount.Password = encriptedPassword; _useraccount.ConfirmPassword = ""; Context.Consultants.Insert(_useraccount); ModelState.Clear(); TempData["Message"] = _useraccount.FirstName + " " + _useraccount.LastName + " נרשם בהצלחה"; return(RedirectToAction("Login")); } TempData["Message"] = "שם משתמש תפוס"; return(View()); }
public ActionResult Login(UserLoginViewModel viewModel) { if (ModelState.IsValid && !UserContext.IsAuthenticated) { var password = EncryptionManager.Encrypt(viewModel.Password); var user = _userRepository.GetUser(viewModel.Email, password); if (user != null && _userRepository.HasUserLoginAccess(user.Id)) { var userAuth = _userRepository.GetUserAuth(user.Id); AuthManager.SetAuthCookie(userAuth.UserData.Email, userAuth.UserData.Id, userAuth.UserData.OrganizationId, true); return(LogInActionResult(userAuth.UserData.Id, viewModel.RedirectUrl)); } else { AddModelError(viewModel, m => m.Password, Dom.Translation.User.LogInError); } } return(View(Mvc.View.User.Login, viewModel)); }
public async Task <bool> UpdatePass(string pass, string newPass, long getUserId) { try { var user = await _manager._context.Users.FindAsync(getUserId); if (user != null) { if (user.Password == EncryptionManager.Encrypt(pass)) { user.Password = EncryptionManager.Encrypt(newPass); } _manager._context.Entry(user).State = EntityState.Modified; } } catch (Exception e) { } return(await _manager.Complete()); }
public static void SetString(string key, string val) { PlayerPrefs.SetString(EncryptionManager.GetHash(key), EncryptionManager.Encrypt(val)); }
public static void SetDouble(string key, double val) { PlayerPrefs.SetString(EncryptionManager.GetHash(key), EncryptionManager.Encrypt(val.ToString())); }
public IDictionary <string, EntityProperty> WriteEntity(OperationContext operationContext) { Dictionary <string, EntityProperty> retVals = new Dictionary <string, EntityProperty>(); #if RT IEnumerable <PropertyInfo> objectProperties = entity.GetType().GetRuntimeProperties(); var classAttributes = System.Attribute.GetCustomAttributes(entity.GetType()); #else IEnumerable <PropertyInfo> objectProperties = this.GetType().GetProperties(); var classAttributes = System.Attribute.GetCustomAttributes(this.GetType()); #endif EncryptionTicks = DateTime.Now.Ticks; EncryptionKey keyAttribute = (EncryptionKey)classAttributes.FirstOrDefault(x => !((x as EncryptionKey)?.IsDefaultValue ?? true)); if (keyAttribute == null) { keyAttribute = (EncryptionKey)classAttributes.First(x => (x as EncryptionKey) != null); keyAttribute = keyAttribute ?? new EncryptionKey(24, 8, 3); } foreach (PropertyInfo property in objectProperties) { // reserved properties if (property.Name == "PartitionKey" || property.Name == "RowKey" || property.Name == "Timestamp" || property.Name == "ETag") { continue; } // Enforce public getter / setter #if RT if (property.SetMethod == null || !property.SetMethod.IsPublic || property.GetMethod == null || !property.GetMethod.IsPublic) #else if (property.GetSetMethod() == null || !property.GetSetMethod().IsPublic || property.GetGetMethod() == null || !property.GetGetMethod().IsPublic) #endif { continue; } EntityProperty newProperty = null; if (property.GetCustomAttribute(typeof(EncryptedProperty)) != null) { EntityProperty ivProperty = null; if (keyAttribute.isSingleKey) { using (var manager = new EncryptionManager(keyAttribute.Key)) { ivProperty = CreateEntityPropertyFromObject(AESEncryptor.CreateInitializor(), false); newProperty = CreateEntityPropertyFromObject(manager.Encrypt(JsonConvert.SerializeObject(property.GetValue(this, null)), ivProperty.StringValue), false); } } else { using (var manager = new EncryptionManager(keyAttribute.A, keyAttribute.B, keyAttribute.C)) { ivProperty = CreateEntityPropertyFromObject(AESEncryptor.CreateInitializor(), false); newProperty = CreateEntityPropertyFromObject(manager.Encrypt(JsonConvert.SerializeObject(property.GetValue(this, null)), ivProperty.StringValue, EncryptionTicks), false); } } if (newProperty != null) { retVals.Add(property.Name + "IV", ivProperty); } } else { newProperty = CreateEntityPropertyFromObject(property.GetValue(this, null), false); } // property will be null if unknown type if (newProperty != null) { retVals.Add(property.Name, newProperty); } } return(retVals); }
public ActionResult ProfileEdit(UserProfileViewModel viewModel) { if (_userRepository.Exists(viewModel.Email, viewModel.Id)) { AddModelError(viewModel, m => m.Email, Dom.Translation.User.DuplicateEmail); } if (ModelState.IsValid && viewModel.Password == viewModel.ConfirmPassword) { User user = _userRepository.Get <User>(viewModel.Id); user.Id = viewModel.Id; user.FirstName = viewModel.FirstName; user.LastName = viewModel.LastName; user.MiddleName = viewModel.MiddleName; user.Email = viewModel.Email; user.Password = EncryptionManager.Encrypt(viewModel.Password); user.DateOfBirth = viewModel.DateOfBirth; user.GenderId = viewModel.GenderId; user.LanguageId = viewModel.LanguageId != 0 ? viewModel.LanguageId : Dom.Language.System; user.Phone = viewModel.Phone; user.Mobile = viewModel.Mobile; user.Salutation = viewModel.Salutation; if (!string.IsNullOrWhiteSpace(viewModel.Address?.FormattedAddress)) { if (user.AddressId != null) { user.Address.City = viewModel.Address.City; user.Address.PostalCode = viewModel.Address.PostalCode; user.Address.Street = viewModel.Address.Street; user.Address.Number = viewModel.Address.Number; user.Address.Latitude = double.Parse(viewModel.Address.Latitude.Replace(".", ",")); user.Address.Longitude = double.Parse(viewModel.Address.Longitude.Replace(".", ",")); user.Address.FormattedAddress = viewModel.Address.FormattedAddress; } else { user.Address = new Address { CountryId = Dom.Country.Ukraine, City = viewModel.Address.City, PostalCode = viewModel.Address.PostalCode, Street = viewModel.Address.Street, Number = viewModel.Address.Number, Latitude = double.Parse(viewModel.Address.Latitude.Replace(".", ",")), Longitude = double.Parse(viewModel.Address.Longitude.Replace(".", ",")), FormattedAddress = viewModel.Address.FormattedAddress }; } } else { if (user.AddressId != null) { _userRepository.Delete(user.Address); user.AddressId = null; } } _userRepository.UnitOfWork.SaveChanges(); } else { viewModel.GenderItems = InitGenderSelectListItems(); viewModel.LanguageItems = InitLanguageSelectListItems(); return(View(Mvc.View.User.ProfileEdit, viewModel)); } return(RedirectToAction(Mvc.Controller.User.Profile, Mvc.Controller.User.Name)); }
public void OrderSystem_UnitTest_Payments_EncryptCreditCard() { string encrypted = EncryptionManager.Encrypt("hello"); Console.Write(encrypted); }
public string Encrypt(string serializedObject, string salt) { return(EncryptionManager.Encrypt(serializedObject, salt)); }
private void btn_Save_Click(object sender, EventArgs e) { try { if (tbFromMail.Text == "") { throw new Exception("From E-Mail is Blank ! Please Fill."); } if (tbFromMailPass.Text == "") { throw new Exception("From Mail Password is Blank ! Please Fill."); } if (tbSmtpHost.Text == "") { throw new Exception("From Smtp Host is Blank ! Please Fill."); } #region SaveEMailSettingsToXML DataTable dtEmail = new DataTable("dtEMail"); dtEmail.Columns.Add("FromEMail"); dtEmail.Columns.Add("Password"); dtEmail.Columns.Add("SmtpHost"); dtEmail.Columns.Add("SmtpPort"); dtEmail.Columns.Add("EnableSSL"); if (!File.Exists("dtEMail.xsd")) { dtEmail.WriteXmlSchema("dtEMail.xsd"); } DataRow dr = dtEmail.NewRow(); dr["FromEMail"] = tbFromMail.Text; dr["Password"] = EncryptionManager.Encrypt(tbFromMailPass.Text); dr["SmtpHost"] = tbSmtpHost.Text; dr["SmtpPort"] = spnSmtpPort.Value.ToString(); if (cbSSL.Checked == true) { dr["EnableSSL"] = "1"; } else { dr["EnableSSL"] = "0"; } dtEmail.Rows.Add(dr); dtEmail.WriteXml("dtEMail.xml"); #endregion saveEMail(tbFromMail.Text, tbFromMailPass.Text, tbSmtpHost.Text, Convert.ToInt32(spnSmtpPort.Value), Convert.ToBoolean(cbSSL.CheckState)); Close(); } catch (Exception ex) { MessageManager.ShowErrorMessage(ex.Message); } }
public ActionResult Add(UserAddViewModel viewModel) { if (_userRepository.Exists(viewModel.Email)) { AddModelError(viewModel, m => m.Email, Dom.Translation.User.DuplicateEmail); } if (ModelState.IsValid) { var user = new User { EntityInfo = EntityInfo.Empty(Dom.EntityType.User.Id), FirstName = viewModel.FirstName, LastName = viewModel.LastName, MiddleName = viewModel.MiddleName, Email = viewModel.Email, Password = EncryptionManager.Encrypt(viewModel.Password), DateOfBirth = viewModel.DateOfBirth, GenderId = viewModel.GenderId, Phone = viewModel.Phone, Mobile = viewModel.Mobile, LanguageId = viewModel.LanguageId != 0 ? viewModel.LanguageId : Dom.Language.System, Salutation = viewModel.Salutation }; if (!string.IsNullOrWhiteSpace(viewModel.Address?.FormattedAddress)) { user.Address.City = viewModel.Address.City; user.Address.PostalCode = viewModel.Address.PostalCode; user.Address.Street = viewModel.Address.Street; user.Address.Number = viewModel.Address.Number; user.Address.Latitude = double.Parse(viewModel.Address.Latitude.Replace(".", ",")); user.Address.Longitude = double.Parse(viewModel.Address.Longitude.Replace(".", ",")); user.Address.FormattedAddress = viewModel.Address.FormattedAddress; } user.UserRoles = new List <UserRole>(); var organizationId = UserContext.User.OrganizationId; if (viewModel.RoleOrganizationId != 0) { viewModel.RoleIds?.ToList().ForEach(r => { user.UserRoles.Add(new UserRole { OrganizationId = viewModel.RoleOrganizationId, RoleId = r }); }); organizationId = viewModel.RoleOrganizationId; } EntityContext.AddEntityProgress(user.EntityInfo, new EntityProgress { OrganizationId = organizationId, EntityStateAfterId = Dom.EntityType.User.State.Created }); EntityContext.AddEntityProgress(user.EntityInfo, new EntityProgress { OrganizationId = organizationId, EntityStateBeforeId = Dom.EntityType.User.State.Created, EntityStateAfterId = Dom.EntityType.User.State.Active }); EntityContext.AddEntityOrganization(user.EntityInfo, organizationId, Dom.EntityType.User.State.Active); _userRepository.AddOrUpdate(user); _userRepository.UnitOfWork.SaveChanges(); return(RedirectToAction(Mvc.Controller.User.List, Mvc.Controller.User.Name)); } ICollection <SelectListItemCount> organizationItems = _organizationRepository.GetOrganizations( UserContext.User.Id, UserContext.User.OrganizationId ); viewModel.OrganizationItems = Mapper.Map <ICollection <SelectListItem> >(organizationItems); ICollection <SelectListItemCount> roleItems = _roleRepository.GetRoles( UserContext.User.Id, UserContext.User.OrganizationId ); viewModel.RoleItems = Mapper.Map <ICollection <SelectListItem> >(roleItems); viewModel.GenderItems = InitGenderSelectListItems(); viewModel.LanguageItems = InitLanguageSelectListItems(); return(View(Mvc.View.User.Add, viewModel)); }
public List <Claim> ValidateUser(string userName, string password, string ipAddress) { return(this.loginDataAccess.ValidateUser(userName, EncryptionManager.Encrypt(password), ipAddress)); }
/// <summary> /// Encrypts a string using an alphabet character array. /// </summary> /// <param name="text"></param> /// <param name="alphabet"></param> /// <returns></returns> public string Encrypt(string text, char[] alphabet) { var manager = new EncryptionManager(); return manager.Encrypt(text, alphabet); }
public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, MediaTypeHeaderValue mediaType) { headers.Add(RestfulServiceConstants.RqModelTypeHeaderKey, EncryptionManager.Encrypt(type.AssemblyQualifiedName)); base.SetDefaultContentHeaders(type, headers, mediaType); }
public ActionResult Edit(UserDetailsViewModel viewModel) { if (_userRepository.Exists(viewModel.Detail.Email, viewModel.Detail.Id)) { AddModelError(viewModel, m => m.Detail.Email, Dom.Translation.User.DuplicateEmail); } if (ModelState.IsValid) { var user = _userRepository.Get <User>(viewModel.Detail.Id); user.FirstName = viewModel.Detail.FirstName; user.LastName = viewModel.Detail.LastName; user.MiddleName = viewModel.Detail.MiddleName; user.Email = viewModel.Detail.Email; user.Password = EncryptionManager.Encrypt(viewModel.Detail.Password); user.DateOfBirth = viewModel.Detail.DateOfBirth; user.GenderId = viewModel.Detail.GenderId; user.Phone = viewModel.Detail.Phone; user.Mobile = viewModel.Detail.Mobile; user.LanguageId = viewModel.Detail.LanguageId != 0 ? viewModel.Detail.LanguageId : Dom.Language.System; user.Salutation = viewModel.Detail.Salutation; if (!string.IsNullOrWhiteSpace(viewModel.Address?.FormattedAddress)) { if (user.AddressId != null) { user.Address.City = viewModel.Address.City; user.Address.PostalCode = viewModel.Address.PostalCode; user.Address.Street = viewModel.Address.Street; user.Address.Number = viewModel.Address.Number; user.Address.Latitude = double.Parse(viewModel.Address.Latitude.Replace(".", ",")); user.Address.Longitude = double.Parse(viewModel.Address.Longitude.Replace(".", ",")); user.Address.FormattedAddress = viewModel.Address.FormattedAddress; } else { user.Address = new Address { CountryId = Dom.Country.Ukraine, City = viewModel.Address.City, PostalCode = viewModel.Address.PostalCode, Street = viewModel.Address.Street, Number = viewModel.Address.Number, Latitude = double.Parse(viewModel.Address.Latitude.Replace(".", ",")), Longitude = double.Parse(viewModel.Address.Longitude.Replace(".", ",")), FormattedAddress = viewModel.Address.FormattedAddress }; } } else { if (user.AddressId != null) { _userRepository.Delete(user.Address); user.AddressId = null; } } if (user.UserRoles != null) { user.UserRoles.ToList().ForEach(x => { _userRepository.Delete(x); }); } else { user.UserRoles = new List <UserRole>(); } if (viewModel.Detail.RoleOrganizationId != 0) { viewModel.Detail.RoleIds?.ToList().ForEach(r => { user.UserRoles.Add(new UserRole { OrganizationId = viewModel.Detail.RoleOrganizationId, RoleId = r }); }); //todo check this in future user.EntityInfo.EntityOrganizations.First().OrganizationId = viewModel.Detail.RoleOrganizationId; } _userRepository.UnitOfWork.SaveChanges(); return(RedirectToAction(Mvc.Controller.User.Details, Mvc.Controller.User.Name, new { id = viewModel.Detail.Id })); } ICollection <SelectListItemCount> organizationItems = _organizationRepository.GetOrganizations( UserContext.User.Id, UserContext.User.OrganizationId ); viewModel.Detail.OrganizationItems = Mapper.Map <ICollection <SelectListItem> >(organizationItems); ICollection <SelectListItemCount> roleItems = _roleRepository.GetRoles( UserContext.User.Id, UserContext.User.OrganizationId ); viewModel.Detail.RoleItems = Mapper.Map <ICollection <SelectListItem> >(roleItems); viewModel.Detail.GenderItems = InitGenderSelectListItems(); viewModel.Detail.LanguageItems = InitLanguageSelectListItems(); return(View(Mvc.View.User.Edit, viewModel)); }