Sowmya Sirsi

Sowmya Sirsi

  • 1.9k
  • 144
  • 6.1k

Generate Random Password Including login username

May 25 2021 9:43 AM
Hi Team,
 
I am stuck with in the fetching the username while generating the new password.
 
Please suggest me. Is there any other option to implement so that it includes username 
 
Code: 
 
protected string RandomPassword(int length)
{
string validChars = lblUserNameData.Text + "0123456789!@#$%^&*?";
Random random = new Random();
char[] chars = new char[length];
for (int i = 0; i < length; i++)
{
chars[i] = validChars[random.Next(0, validChars.Length)];
}
return new string(chars);
}
 
protected void btnSubmit_Click(object sender, EventArgs e)
{
int length = 10;
log.Debug("Entering btnSubmit_Click");
string NewPwd = RandomPassword(length);
 
 

Answers (1)