Random Password Generator

Hi friend ,
Here i am giving you a C# function which is used to generate random password . It might be between 1 to 9,a to z, A to Z . new password is a combination of all these characters.
 look @ the function,


private string Random_Password()
   { 
 int passwordLength = 8; //This is the length of your password
      string passwordChar = "";
      passwordChar = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,";
      passwordChar += "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,";
      passwordChar += "1,2,3,4,5,6,7,8,9,0";
      char[] sep = { ',' };
      string[] arr = passwordChar.Split(sep);
      string passwordString = "";
      string temp = "";             
      Random rand = new Random();
      for(int i = 0; i < Convert.ToInt32(passwordLength.ToString()); i++)
           {
             temp = arr[rand.Next(0, arr.Length)];
             passwordString += temp;
            }

            return passwordString;
   }

This function will return a 8 digit alpha numeric password . hope this will help you in your project.

Regards,

Rajesh

1 comment: