javascript密码生成器 [英] javascript password generator
本文介绍了javascript密码生成器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
创建包含 az
, AZ
和<$ c的8个字符随机密码的最佳方法是什么? $ c> 0-9 ?
绝对没有安全问题,这只是用于原型设计,我只想要看起来真实的数据。
Absolutely no security issues, this is merely for prototyping, I just want data that looks realistic.
我在考虑($到7)Math.random 的来生成ASCII码并将它们转换为字符。你还有其他的建议吗?
I was thinking a for (0 to 7) Math.random
to produce ASCII codes and convert them to characters. Do you have any other suggestions?
推荐答案
我可能会用这样的东西:
I would probably use something like this:
function generatePassword() {
var length = 8,
charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
retVal = "";
for (var i = 0, n = charset.length; i < length; ++i) {
retVal += charset.charAt(Math.floor(Math.random() * n));
}
return retVal;
}
然后可以将其扩展为通过参数传递长度和字符集。
That can then be extended to have the length and charset passed by a parameter.
这篇关于javascript密码生成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文