Question

No need to write it again... the question says it all.

Was it helpful?

Solution

Here's a nice article that might help you.

OTHER TIPS

You can use the built-in function included in the namespace System.Web.Security.

Membership.GeneratePassword Method
Generates a random password of the specified length.

In the past I've done it once by using a piece of a Guid. I just created a new guid, converted it to a string and took the piece I wanted, I think I used the characters in the back, or the other way around. Tested it with 100 loops and every time the string was different.

Doesn't has anything to do with MVC though...

 public string CreatePassword(int length)
    {
        const string valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
        StringBuilder res = new StringBuilder();
        Random rnd = new Random();
        while (0 < length--)
        {
            res.Append(valid[rnd.Next(valid.Length)]);
        }
        return res.ToString();
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top