Creating auto generated string password in ASP.NET

Recently i did a small snippet of program where we had to autogenerate a password randomly which could be emailed to users. Here is the simple logic required to do so. Please do let me know if there are areas for improvement.

Code in C#

string allowedChars = “”;
allowedChars = “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,”;
allowedChars += “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,”;
allowedChars += “1,2,3,4,5,6,7,8,9,0,!,@,#,$,%,&,?”;
char[] sep = { ‘,’ };
string[] arr = allowedChars.Split(sep);
string passwordString = “”;
string temp1 = “”;
Random rand = new Random();
for (int i = 0; i < 5; i++)
{
temp1 = arr[rand.Next(0, arr.Length)];
passwordString += temp1;

}

VN:F [1.9.16_1159]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.16_1159]
Rating: 0 (from 0 votes)

Like this blog? Subscribe for more