password generator in c#
<p>I want to create a random password generator in my ASP.NET C# web application.</p>

<p>I have created that but it is applicable only for the integer format. If I give any characters it shows the debugging error as "my input format is wrong".</p>

<p>But i want to enter both string and integer. For example my textbox field may be </p>

<blockquote>
  <p>dft-001</p>
</blockquote>

<p>I want a random password for this value and also my length should be restricted to 8 digits or characters only.</p>

<p>My current code:</p>

<pre><code>public static string CreateRandomPassword(int PasswordLength)
    {

        string _allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789-";
        Random randNum = new Random();
        char[] chars = new char[PasswordLength];
        int allowedCharCount = _allowedChars.Length;

        for (int i = 0; i &lt; PasswordLength; i++)
        {
            chars[i] = _allowedChars[(int)((_allowedChars.Length) * randNum.NextDouble())];
        }

        return new string(chars);
    }


protected void Button1_Click(object sender, EventArgs e)
    {
        userid.Text = "Your id is:     " + id.Text;
        if(id .Text!="")
        {

            string myInt = id.Text.ToString(); 
            password.Text = "Your password is: " + CreateRandomPassword(int.Parse(myInt)); 
        }
       }
</code></pre>
