ActionScript 3 AS3创建随机密码
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 AS3创建随机密码相关的知识,希望对你有一定的参考价值。
function createRandomPassword(hashLen:uint, includeLowercase:Boolean = true, includeNumbers:Boolean = true, includeUppercase:Boolean = false):String {
var strHash:String = "";
if (includeLowercase) strHash += "abchefghjkmnpqrstuvwxyz";
if (includeNumbers) strHash += "0123456789";
if (includeUppercase) strHash += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var maskPick:Number;
var passwordStr:String = "";
var maskLen:uint = strHash.length;
for (var i:uint = 0; i < hashLen; i++) {
maskPick = Math.floor(Math.random() * maskLen);
passwordStr += strHash.charAt(maskPick);
}
return passwordStr;
}
trace(createRandomPassword(8));
// Output
// 6k3x10h8j
trace(createRandomPassword(6, true, true, true));
// Output
// D2jHEfT
trace(createRandomPassword(16, false, true, true));
// Output
// O8I2DTSLHHWRI50Z
trace(createRandomPassword(16, true, false, false));
// Output
// xxfeyshhqkrsqvhjt
trace(createRandomPassword(16, false, false, true));
// Output
// XMXIDTIXMNGNUXZT
trace(createRandomPassword(16, false, true, false));
// Output
// 4026352375069424
以上是关于ActionScript 3 AS3创建随机密码的主要内容,如果未能解决你的问题,请参考以下文章
ActionScript 3 AS3随机颜色
ActionScript 3 AS3随机化数组
ActionScript 3 AS3随机范围
ActionScript 3 AS3随机方法实用工具类
ActionScript 3 AS3密码强度计
ActionScript 3 AS3:创建渐变矩形