public User Login(string username, string password) { try { using (ApplicationUnit unit = new ApplicationUnit()) { User loginUser = unit.Users.GetAll() .FirstOrDefault(usr => usr.Username.ToLower() == username.ToLower()); if (loginUser != null) { string decriptedPassword = EncryptString.Decrypt(loginUser.Password, "THEPROJECT"); if (decriptedPassword == password) { Task addTask = new Task(() => LogAuditTrail("Login", string.Format("Successful Login {0}", loginUser.Username), loginUser.Id, loginUser.Id)); addTask.Start(); return(loginUser); } } return(null); } } catch (Exception ex) { ErrorHandling.LogError(ex.StackTrace, "AddBuilding"); throw ex; } }
public void EncryptDecrypt(string TestValue, string Key) { //Use a for loop to simulate gen sequence. var encryptString1 = EncryptString.Encrypt(TestValue, Key, 1000); var encryptString2 = EncryptString.Encrypt(TestValue, Key, 1000); Assert.False(string.IsNullOrEmpty(encryptString1)); Assert.False(string.IsNullOrEmpty(encryptString2)); Assert.NotEqual(encryptString1, encryptString2); //encryption is salted, so two encryptions should not be the same; output.WriteLine("Encrypt success."); //decrypt var decryptString1 = EncryptString.Decrypt(encryptString1, Key, 1000); Assert.Equal(TestValue, decryptString1); output.WriteLine("Decrypt1 success."); //decypt with modified key. this will usually throw, due to incompatible key. when is does pass, ensure the values are not the same. try { var decryptstring = EncryptString.Decrypt(encryptString1, Key + " ", 1000); Assert.NotEqual(decryptstring, TestValue); } catch (Exception ex) { } output.WriteLine("Decrypt2 success."); }
public bool Decrypt(string key) { if (!string.IsNullOrEmpty(SecurityKeyEncrypted)) { SecurityKey = EncryptString.Decrypt(SecurityKeyEncrypted, key); } if (!string.IsNullOrEmpty(EncryptionKeyEncrypted)) { EncryptionKey = EncryptString.Decrypt(EncryptionKeyEncrypted, key); } return(true); }
public string GetConnectionString(string key, int iterations) { // if(string.IsNullOrEmpty(ConnectionStringRaw)) // { // if(string.IsNullOrEmpty(ConnectionString)) // { // return ""; // } // // if (UseConnectionStringVariable) // { // return ConnectionString; // } return(EncryptString.Decrypt(ConnectionString, key, iterations)); // } // return ConnectionStringRaw; }
public static XmlDocument GetXmlDocument(string absoluteFilePath) { XmlDocument result; if (!File.Exists(absoluteFilePath)) { Debug.Log("null"); result = null; } else { XmlDocument xmlDocument = new XmlDocument(); FileStream fileStream = new FileStream(absoluteFilePath, FileMode.Open, FileAccess.Read); BinaryReader binaryReader = new BinaryReader(fileStream); uint num = binaryReader.ReadUInt32(); if (4294967295u == num) { DateTime now = DateTime.Now; for (int i = 0; i <= 5120; i++) { int num2 = binaryReader.Read(XmlResAdapter.s_buffer, i * 1024, 1024); if (num2 < 1024) { byte[] array = new byte[1024 * i + num2]; Array.Copy(XmlResAdapter.s_buffer, array, array.Length); string xml = EncryptString.Decrypt(array, XmlResAdapter.s_encryptedKey); xmlDocument.LoadXml(xml); if ((DateTime.Now - now).TotalMilliseconds > 50.0) { } goto IL_129; } } fileStream.Close(); binaryReader.Close(); result = null; return(result); } xmlDocument.Load(absoluteFilePath); IL_129: fileStream.Close(); binaryReader.Close(); result = xmlDocument; } return(result); }
public string GetPassword(string key, int iterations) { // if(string.IsNullOrEmpty(PasswordRaw)) // { // if(string.IsNullOrEmpty(Password)) // { // return ""; // } // // if (UsePasswordVariable) // { // return Password; // } return(EncryptString.Decrypt(Password, key, iterations)); // } // return PasswordRaw; }
public bool ResertPassword(string username) { using (ApplicationUnit unit = new ApplicationUnit()) { User foundUser = unit.Users.GetAll().FirstOrDefault(user => user.Username.ToLower() == username.ToLower()); if (foundUser != null) { string decriptedPassword = EncryptString.Decrypt(foundUser.Password, "THEPROJECT"); EmailService emailService = new EmailService(); //Send Email with Invoice Task sendEmailTask = new Task(() => emailService.SendResertPasswordEmail(foundUser.Email, decriptedPassword)); // Start the task. sendEmailTask.Start(); return(true); } return(false); } }
/// <summary> /// 执行检查 /// </summary> /// <returns></returns> private bool GetCheckResult() { string field = Request["field"]; string validate = Request["validate"]; if (!string.IsNullOrEmpty(field) && !string.IsNullOrEmpty(validate)) { Account accountModel = AccountHelper.GetAccount(field, null); if (accountModel == null) { ChangePnlVisible(5, "验证错误!"); return(false); } string validatePWD = ""; try { validatePWD = EncryptString.Decrypt(validate); } catch (Exception ex) { ChangePnlVisible(5, "验证错误!"); return(false); } if (accountModel.Password != validatePWD) { ChangePnlVisible(5, "错误,此验证已过期!"); return(false); } ChangePnlVisible(3, accountModel.LoginName); } else { ChangePnlVisible(1, ""); } return(true); }
public string GetValue(string key, int iterations) { string value; if (IsEncrypted) { if (string.IsNullOrEmpty(ValueRaw)) { if (string.IsNullOrEmpty(Value)) { value = ""; } else { value = EncryptString.Decrypt(Value, key, iterations); } } else { value = ValueRaw; } } else { value = Value; } if (IsEnvironmentVariable) { return(Environment.GetEnvironmentVariable(value)); } else { return(value); } }
public void DecryptBadText() { Assert.Throws <InvalidEncryptionTextException>(() => EncryptString.Decrypt("1231231", "key", 100)); }
public void DecryptBadKey() { var value = EncryptString.Encrypt("test value", "key", 100); Assert.Throws <InvalidEncryptionTextException>(() => EncryptString.Decrypt(value, "badKey", 100)); }
public string Decrypt(string value, string key) { return(EncryptString.Decrypt(value, key, 1000)); }