Thursday 18 August 2016

Random Password Generation in C#

Posted by : Manav Pandya




Random Password Generation in C#

In this tutorial i am trying to make easy password generation procedure either any of the field like :


  • User ID
  • Payment / Reservation Number
  • Travel ID
  • Patient ID
  • Product Number
  • Reciept Number


I have used simple logic here by using 1 to 9 number and alpha's , so that desired random number should be generated on basis of our criteria .



    public static string GetRandomPassword(int length)
    {
        char[] chars = "$%#@!*abcdefghijklmnopqrstuvwxyz1234567890?;:ABCDEFGHIJKLMNOPQRSTUVWXYZ^&".ToCharArray();
        string password = string.Empty;
        Random random = new Random();

        for (int i = 0; i < length; i++)
        {
            int x = random.Next(1,chars.Length);
            //Don't Allow Repetation of Characters
            if (!password.Contains(chars.GetValue(x).ToString()))
                password += chars.GetValue(x);
            else
                i--;
        }      
        return password;
    }


You may also like : Hello World Application C# R


Whatsapp Messages, Whatsapp Images, Whatsapp Status, Whatsapp DP, Good morning images, Good morning ganesha, whatsapp ganesha, good morning shiva, whatsapp shiva, jai shri krishna, whatsapp krishna, Jai shri ram, Jai hanuman images, jai mata di, motivational messages, whatsapp motivational images, whatsapp funny messages, bajarangbali images, saibaba images, moraribapu images, moraribapu quotes, Guajarati images, Hindi images, gujarati messages, hindi messages, ganesh chaturthi images, vinayak chaturthi images, ramnavami images, navratri images, raksha bandhan images, friendship day images, independence day images, republic day images, Indian national flag, happy makar sankranti images, uttarayan messages, Happy Holi Images, Valentine Day images, Diwali wishes, Happy Dipavali Images, Happy Dhanteras Images, happy janmashtami images, jalarambapa images, Happy Sunday Images, Happy Thursday Images, Happy Saturday Images,

ASP.NET , What is C# , Hello World app in C# , ASP.NET MVC Tutorials , C# Tutorials , Demo Project , Web API , MVC 4.0 , .NET Core 

andom Password generation in C# , What is C# , ASP.NET WITH C# , ASP.NET MVC , AngularJS , Bootstrap