如何在asp.net mvc应用程序中自动生成随机密码?

时间:2022-11-01 04:12:27

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

不需要再写了......问题就是这么说的。

4 个解决方案

#1


7  

Here's a nice article that might help you.

这是一篇可能对你有帮助的好文章。

#2


14  

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

您可以使用命名空间System.Web.Security中包含的内置函数。

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

Membership.GeneratePassword方法生成指定长度的随机密码。

#3


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.

在过去,我曾经使用一块Guid做过一次。我刚刚创建了一个新的guid,将它转换成一个字符串并取出了我想要的那个,我想我在后面使用了字符,或者反过来。用100个循环测试它,每次字符串不同。

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

与MVC没有任何关系......

#4


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

#1


7  

Here's a nice article that might help you.

这是一篇可能对你有帮助的好文章。

#2


14  

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

您可以使用命名空间System.Web.Security中包含的内置函数。

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

Membership.GeneratePassword方法生成指定长度的随机密码。

#3


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.

在过去,我曾经使用一块Guid做过一次。我刚刚创建了一个新的guid,将它转换成一个字符串并取出了我想要的那个,我想我在后面使用了字符,或者反过来。用100个循环测试它,每次字符串不同。

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

与MVC没有任何关系......

#4


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