-1

In my application, the admin have to create many users and for that I want my system to auto generate secure random password temporarily when the admin click on the create user button. When the new user will enter the website with the auto generated website he will be request to change his password.

I am stuck on how to make this process, does the auto generated password have to be save in the database when the admin created it or there is another way for that?

Are there any methods for the creation of auto generated password?

  • Please read [this](https://security.stackexchange.com/questions/17979/is-sending-password-to-user-email-secure) and [this](https://security.stackexchange.com/questions/121121/sending-server-generated-password-by-email). – JHBonarius Sep 09 '21 at 07:46

1 Answers1

-1

This Code will generate a random alphanumeric password of the specified length. You need to pass the password length in the method parameter.

private static Random random = new Random();
public static string GenerateRandomPassword(int length)
{
    const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    return new string(Enumerable.Repeat(chars, length)
      .Select(s => s[random.Next(s.Length)]).ToArray());
}
Bluemarble
  • 1,925
  • 4
  • 20
  • 35
  • 2
    This is almost a literal copy of [this answer](https://stackoverflow.com/a/1344242). You should cite your sources. Else it's just IP theft – JHBonarius Sep 09 '21 at 07:48