Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Linq;
- using System.Web;
- public class PasswordGenerator
- {
- int seed;
- public PasswordGenerator(int seed)
- {
- this.seed = seed;
- }
- public String getPassword()
- {
- string allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789";
- int passwordLength = System.Convert.ToInt32(ConfigurationManager.AppSettings["PasswordLength"].ToString());
- char[] chars = new char[passwordLength];
- Random rd;
- DateTime now = DateTime.Now;
- seed = seed * (now.Year + now.Month + now.Day + now.Hour + now.Minute + now.Second + now.Millisecond);
- rd = new Random(seed);
- chars[0] = allowedChars[rd.Next(0, allowedChars.Length - 10)];
- for (int i = 1; i < passwordLength; i++)
- {
- chars[i] = allowedChars[rd.Next(0, allowedChars.Length)];
- }
- return new string(chars);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement