OTP (One Time Password) in Asp.NET

  1. private string generatePassword()   
  2. {  
  3.     int lenthofpass = 6;  
  4.     string allowedChars = "";  
  5.     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,";  
  6.     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,";  
  7.     allowedChars += "1,2,3,4,5,6,7,8,9,0,!,@,#,$,%,&,?";  
  8.     char[] sep =   
  9.     {  
  10.         ','  
  11.     };  
  12.     string[] arr = allowedChars.Split(sep);  
  13.     string passwordString = "";  
  14.     string temp = "";  
  15.     Random rand = new Random();  
  16.     for (int i = 0; i < lenthofpass; i++)  
  17.     {  
  18.         temp = arr[rand.Next(0, arr.Length)];  
  19.         passwordString += temp;  
  20.     }  
  21.     return passwordString;  
  22. }