Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How to compare encrypted password in sql
- string userName = txtusername.Text;
- string password = txtpassword.Text;
- Encryptor en = new Encryptor(EncryptionAlgorithm.Rc2, CreateRandomPassword(7));
- password = en.Encrypt(password);
- DataTable dt = uMManager.ValidateUser(userName, password);
- private static string CreateRandomPassword(int passwordLength)
- {
- string allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789!@$?_-";
- char[] chars = new char[passwordLength];
- Random rd = new Random();
- for (int i = 0; i < passwordLength; i++)
- {
- chars[i] = allowedChars[rd.Next(0, allowedChars.Length)];
- }
- return new string(chars);
- }
- public class Encryptor
- {
- EncryptEngine engin;
- public byte[] IV;
- public Encryptor(EncryptionAlgorithm algID, string key)
- {
- engin = new EncryptEngine(algID, key);
- }
- public EncryptEngine EncryptEngine
- {
- get
- {
- return engin;
- }
- set
- {
- engin = value;
- }
- }
- public string Encrypt(string MainString)
- {
- MemoryStream memory = new MemoryStream();
- CryptoStream stream = new CryptoStream(memory, engin.GetCryptTransform(), CryptoStreamMode.Write);
- StreamWriter streamwriter = new StreamWriter(stream);
- streamwriter.WriteLine(MainString);
- streamwriter.Close();
- stream.Close();
- IV = engin.Vector;
- byte[] buffer = memory.ToArray();
- memory.Close();
- return Convert.ToBase64String(buffer);
- }
- }
Add Comment
Please, Sign In to add comment