密码生成器的代码
我正在开发一个 C# 项目,需要生成随机密码。
任何人都可以提供一些代码或高级密码生成方法吗?
应该可以指定以下内容:
- 最小密码长度
- 最大密码长度
- 有效的大写字符
- 大写字符的最小数量
- 有效的小写字符
- 最小的小写字符数量
- 有效的数字字符
- 数字字符的最小数量
- 有效的阿尔法字符。
- 最小阿尔法字符数
I'm working on a C# project where I need to generate random passwords.
Can anyone provide some code or a high-level approach for password generation?
It should be possible to specify the following:
- Minimum password length
- Maximum password length
- Valid uppercase characters
- Minimum number of uppercase chars
- Valid lowercase chars
- Minimum number of lowercase chars
- Valid numeric chars
- Minimum number of numeric chars
- Valid alfanum chars.
- Minimum number of alfanum chars
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用此方法并根据您的需要进行修改
you can use this method and modify according to your need
我很久以前编写了一个简单的数据生成库来模拟我们需要的一些数据,您可以看一下它以获得一些想法。您向它提供要生成的模式,它将创建随机数据来匹配该模式。
模式如下:
它并不完全是您正在寻找的内容,但您应该能够对其进行修改以满足您的需求。
这是主要逻辑
编辑:再次阅读您的要求,我认为您应该能够更改我的代码以使其正常工作。您需要创建一个匹配有效密码的最小字符/数字要求的模式,添加逻辑以通过添加随机字符来改变生成的密码的长度,并且可能在末尾添加一些随机排序逻辑来混合字符以便它们不总是处于相同的模式。
编辑(2):将代码移至 GitHub,更新了链接。
编辑(3):链接到主 Github 存储库。
I wrote a simple Data generation library ages ago to mock up some data we needed, you could take a look at that to get some ideas. You provide it with a pattern which you want to generate and it will create random data to match that pattern.
The pattern is as follows:
Its not exactly what you are looking for but you should be able to modify it to suit your needs.
This is the main logic
EDIT: Reading through your requirements again I think you should be able to alter my code to get it to work. You would need to create a pattern that matches the minimum character/number requirements for a valid password, add logic to vary the length of the generated password by adding in random characters, and perhaps add some random sort logic at the end to mix the characters up so that they are not always in the same pattern.
EDIT(2): Moved the code to GitHub, updated links.
EDIT(3): Linked to main Github repo instead.
AC# 密码生成器
我还发现
http://www.codeproject.com/KB/cs/password-generator.aspx
http://www.codesnipr.com/snippet/504/c-随机密码生成器
http: //www.yetanotherchris.me/home/2009/3/15/c-pronounceable-password-generator.html
A C# Password Generator
I found also
http://www.codeproject.com/KB/cs/password-generator.aspx
http://www.codesnipr.com/snippet/504/c-Random-password-generator
http://www.yetanotherchris.me/home/2009/3/15/c-pronounceable-password-generator.html
从代码项目中取出密码生成器,清理代码并修复最大属性设置器中的逻辑错误。
Took the password generator from code project, cleaned up the code and fixed a logic fault in the Maximum property setter.