Advertisement
HenX

Password

Sep 25th, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Linq;
  5. using System.Web;
  6.  
  7. public class PasswordGenerator
  8. {
  9.     int seed;
  10.  
  11.     public PasswordGenerator(int seed)
  12.     {
  13.         this.seed = seed;
  14.     }
  15.    
  16.  
  17.     public String getPassword()
  18.     {
  19.         string allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789";
  20.         int passwordLength = System.Convert.ToInt32(ConfigurationManager.AppSettings["PasswordLength"].ToString());
  21.         char[] chars = new char[passwordLength];
  22.        
  23.         Random rd;
  24.         DateTime now = DateTime.Now;
  25.  
  26.         seed = seed * (now.Year + now.Month + now.Day + now.Hour + now.Minute + now.Second + now.Millisecond);
  27.        
  28.  
  29.         rd = new Random(seed);
  30.  
  31.         chars[0] = allowedChars[rd.Next(0, allowedChars.Length - 10)];
  32.         for (int i = 1; i < passwordLength; i++)
  33.         {
  34.             chars[i] = allowedChars[rd.Next(0, allowedChars.Length)];
  35.         }
  36.  
  37.         return new string(chars);
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement