private void SqlConnectionForm_Load(object sender, EventArgs e) { if (settings != null) { if (settings.SQLServAddr != null) { ServerName.Text = settings.SQLServAddr; } if (settings.IsSQLTypeAuth) { SQLServeAuthRB.Checked = true; Login.Text = settings.SQLLogin; } else { WindowsAuthRB.Checked = true; } if (settings.SQLDBName != null) { DBNames.Text = settings.SQLDBName; } if (settings.SQLPassword != null) { Password.Text = BaseEncryptor <System.Security.Cryptography.DESCryptoServiceProvider> .Decrypt(settings.SQLPassword); } } }
private bool CheckConnection() { GenerateConnection(); if (!string.IsNullOrEmpty(Password.Text)) { settings.SQLPassword = BaseEncryptor <System.Security.Cryptography.DESCryptoServiceProvider> .Encrypt(Password.Text); } try { _conn.Open(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } _conn.Close(); settings.SQLServAddr = ServerName.Text; settings.IsSQLTypeAuth = SQLServeAuthRB.Checked; if (SQLServeAuthRB.Checked) { settings.SQLLogin = Login.Text; } else { settings.SQLLogin = null; } settings.SQLDBName = DBNames.Text; settings.Save(); isCheckconnectionPressed = true; return(true); }
public static BaseEncryptor GetEncryptor(Encryptor encryptor) { BaseEncryptor cryptoProvider = null; if (encryptor == Encryptor.Aes) { if (rijndaelEncryptor == null) { rijndaelEncryptor = new RijndaelEncryptor(); } cryptoProvider = rijndaelEncryptor; } if (encryptor == Encryptor.Des) { if (dataEncryptor == null) { dataEncryptor = new DataEncryptor(); } cryptoProvider = dataEncryptor; } if (encryptor == Encryptor.Hash) { if (hashEncryptor == null) { hashEncryptor = new HashEncryptor(); } cryptoProvider = hashEncryptor; } return(cryptoProvider); }
public static bool ValidateUser(string username, string password) { bool result = false; BaseEncryptor cryptoProvider = CryptoManager.GetEncryptor(Encryptor.Md5); string encryptedPassword = cryptoProvider.Encrypt(password); User user = Users.ValidateUser(username, encryptedPassword); if (user != null) { result = true; } return(result); }
/// <summary> /// Creates a user /// </summary> /// <param name="email"></param> /// <param name="password"></param> /// <param name="role"></param> /// <returns>User</returns> public static User CreateUser(string email, string password, RoleType role) { BaseEncryptor cryptoProvider = CryptoManager.GetEncryptor(Encryptor.Md5); User user = new User(); user.UserUid = Guid.NewGuid(); user.Email = email; user.Role = role; user.UserState = UserState.Online; user.AccountState = AccountState.Enabled; user.Pass = cryptoProvider.Encrypt(password); user = Users.CreateUser(user); return(user); }
/// <summary> /// Creates a user /// </summary> /// <param name="email"></param> /// <param name="password"></param> /// <param name="fullName"></param> /// <param name="phone"></param> /// <param name="role"></param> /// <returns>User</returns> public static User CreateUser(string email, string password, string fullName, string phone, Roles role) { BaseEncryptor cryptoProvider = CryptoManager.GetEncryptor(Encryptor.Hash); User user = new User(); user.Email = email; user.FullName = fullName; user.Phone = phone; user.Role = role; user.AccountState = AccountState.Enabled; user.Password = cryptoProvider.Encrypt(password); user = Users.CreateUser(user); return(user); }
public void decrypt_image_test() { BaseEncryptor baseEncryptor = new BaseEncryptor(); RgbConverter rgbConverter = new RgbConverter(); Bitmap bitmap = rgbConverter.ToBitmap(baseEncryptor.Encrypt("test")); List <int> rgbDifferences = _encrypter.Parse(bitmap); string exp = "z"; string expBinary = StringUtil.RemoveSpaces("01110100 01100101 01110011 01110100 "); List <int> diffs = new List <int>(); expBinary.ToList().ForEach(x => diffs.Add(int.Parse(x.ToString()))); for (int i = 0; i < diffs.Count; i++) { Assert.Equal(diffs[i], rgbDifferences[i]); } }