Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

how to generate random password in c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Generate_Randon_password
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Random myRandom = new System.Random();
            int myLength = myRandom.Next(6, 10);
            string Mypassword = "";
            while (myPassword.Length
            {
                int myPick = myRandom.Next(1, 3);

                if (myPick == 1)
                {
                    // Add a random number to the string.
                    myPassword += (char)myRandom.Next(48, 57);
                }
                else if (myPick == 2)
                {
                    // Add a random lower case letter to the string.

                    myPassword += (char)myRandom.Next(97, 122);
                }
                else if (myPick == 3)
                {
                    // Add a random upper case letter to the string.

                    myPassword += (char)myRandom.Next(65, 90);
                }
            }

            Console.WriteLine("Your Random PassWord is : "+myPassword.ToString());
            Console.ReadKey();
        }
    }
    }













Read more »


This post first appeared on Dot Net Tutorial For Beginners With Examples, please read the originial post: here

Share the post

how to generate random password in c#

×

Subscribe to Dot Net Tutorial For Beginners With Examples

Get updates delivered right to your inbox!

Thank you for your subscription

×