7

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

4 Answers 4

15

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.

Sign up to request clarification or add additional context in comments.

Comments

7

Here's a nice article that might help you.

Comments

2

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...

Comments

0
 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();
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.