Guest User

Untitled

a guest
Aug 22nd, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. How to compare encrypted password in sql
  2. string userName = txtusername.Text;
  3. string password = txtpassword.Text;
  4. Encryptor en = new Encryptor(EncryptionAlgorithm.Rc2, CreateRandomPassword(7));
  5. password = en.Encrypt(password);
  6. DataTable dt = uMManager.ValidateUser(userName, password);
  7.  
  8. private static string CreateRandomPassword(int passwordLength)
  9. {
  10. string allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789!@$?_-";
  11. char[] chars = new char[passwordLength];
  12. Random rd = new Random();
  13.  
  14. for (int i = 0; i < passwordLength; i++)
  15. {
  16. chars[i] = allowedChars[rd.Next(0, allowedChars.Length)];
  17. }
  18. return new string(chars);
  19. }
  20.  
  21. public class Encryptor
  22. {
  23. EncryptEngine engin;
  24. public byte[] IV;
  25.  
  26. public Encryptor(EncryptionAlgorithm algID, string key)
  27. {
  28. engin = new EncryptEngine(algID, key);
  29. }
  30.  
  31. public EncryptEngine EncryptEngine
  32. {
  33. get
  34. {
  35. return engin;
  36. }
  37. set
  38. {
  39. engin = value;
  40. }
  41. }
  42.  
  43. public string Encrypt(string MainString)
  44. {
  45. MemoryStream memory = new MemoryStream();
  46. CryptoStream stream = new CryptoStream(memory, engin.GetCryptTransform(), CryptoStreamMode.Write);
  47. StreamWriter streamwriter = new StreamWriter(stream);
  48. streamwriter.WriteLine(MainString);
  49. streamwriter.Close();
  50. stream.Close();
  51. IV = engin.Vector;
  52. byte[] buffer = memory.ToArray();
  53. memory.Close();
  54. return Convert.ToBase64String(buffer);
  55.  
  56. }
  57. }
Add Comment
Please, Sign In to add comment