Advertisement
Ortund

Untitled

Jul 5th, 2016
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. /// <summary>
  2. /// Uses CreateKey to generate a 10-character long password string
  3. /// </summary>
  4. /// <returns>Random string value eg. xX*tjoqOVw</returns>
  5. public static string CreatePasswordString()
  6. {
  7.     string Chars = @"~`!@#$%^&*()\/',.?;:|";
  8.     var RNG = new Random();
  9.  
  10.     // Select a character to insert into the password
  11.     string Character = new String(Enumerable.Repeat(Chars, 1).Select(s => s[RNG.Next(s.Length)]).ToArray());
  12.  
  13.     return CreateKey(9).Insert(RNG.Next(9), Character);
  14. }
  15.  
  16. /// <summary>
  17. /// Runs the specifed password through bcrypt hashing
  18. /// </summary>
  19. /// <param name="password"></param>
  20. /// <returns></returns>
  21. public static string CreatePassword(string password)
  22. {
  23.     byte[] PasswordBytes = Encoding.ASCII.GetBytes(password);
  24.  
  25.     // no need to generate a salt value since bcrypt does that all on its own
  26.     return Crypter.Blowfish.Crypt(PasswordBytes);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement