title: Generate password in C#
body: <p>I want to generate password in c# with atleast one upper case alphabet, one lower case alphabet,one special character and one numeric value.</p>
  <p>and length should be 16 characterLong</p>
  <p>like
  string pwd =&quot;Stackflow#202230&quot;</p>
  <p><em>edit</em></p>
  <pre class="lang-cs prettyprint-override"><code>Random rndpass = new Random();
  
  string allowedChars = &quot;&quot;;
  
  string allowedCapitalChars = &quot;&quot;;
  
  allowedChars &quot;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,&quot;;
  allowedChars +=&quot;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,&quot;;
  allowedChars += &quot;1,2,3,4,5,6,7,8,9,0,&quot;;
  allowedChars += &quot;!,@,#,$,%,&amp;,?,&quot;;
  
  allowedCapitalChars +=&quot;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&quot;;
  
  char[] sep = { ',' };
  string[] arr = allowedChars.Split(sep);
  string[] arrs = allowedCapitalChars.Split(sep);
  string passwordString = &quot;&quot;;
  string temp = &quot;&quot;;
  for (int i = 0; i &lt; 1; i++)
  {
      temp = arr[rndpass.Next(0, arrs.Length)];
      passwordString += temp;
  }
  for (int i = 1; i &lt; 16; i++)
  {
      temp = arr[rndpass.Next(0, arr.Length)];
      passwordString += temp;
  }             
  randomPassword = passwordString;                
  </code></pre>