Wednesday, 4 October 2017

Method for Create Dynamic Alpha Numeric Password in C#

Method for Create Dynamic Alpha Numeric Password in C#

This Method returns a dynamic String:-

  public static string CreateDynamicPassword()
        {
            string _allowedChars =                               "0123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ";
            Random randNum = new Random();
            char[] chars = new char[8];
            int allowedCharCount = _allowedChars.Length;
            for (int i = 0; i < 8; i++)
            {
                chars[i] = _allowedChars[(int)((_allowedChars.Length) * randNum.NextDouble())];
            }
            return new string(chars);
        }