这期内容当中小编将会给大家带来有关怎么在JS中以SQL方式随机生成高强度密码,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
JS方式
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>随机生成密码</title> </head> <body> <input type="button" onclick="RanPwd()" value="生成密码" /> <span id="pwd"></span> <script> var numChar = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; var alphChar = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; var syblChar = ['~', '!', '@', '#', '$', '%', '^', '&', '*', '-', '+', '?', '¥', ';', '"', '<', '>', '|']; function generatePwd() { var res = ""; for(let i = 0; i < 2; i++) { var id = Math.floor(Math.random() * 10); res += numChar[id]; } for(let j = 0; j < 3; j++) { var id = Math.floor(Math.random() * 26); res += alphChar[id]; } for(let k = 0; k < 1; k++) { var id = Math.floor(Math.random() * 18); res += syblChar[id]; } return res; } function strengthPwd(pwd) { var len = n = pwd.length-1; pwd = pwd.split(""); var newPwd = ""; for(var i = 0; i <= len; i++) { var id = Math.floor(Math.random() * n) newPwd += pwd.splice(id,1); n--; } return newPwd; } function RanPwd(){ var prePwd = generatePwd(); var pwd = strengthPwd(prePwd); document.getElementById("pwd").innerHTML = pwd; } </script> </body> </html>
这里使用在线HTML/CSS/JavaScript代码运行工具:http://tools.jb51.net/code/HtmlJsRun测试上述代码,可得如下运行结果:
SQL方式
--生成高强度的随机密码 declare @strPwd varchar(82) declare @i int declare @n int declare @Index int declare @pwd varchar(6) declare @newPwd varchar(6) set @i = 0 set @pwd = '' set @newPwd = '' set @strPwd = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$%^&*-=+?.,;:|><' while (@i < 6) begin if(@i<2) begin set @Index = ceiling((rand() * 10)) end else if(@i<5 and @i>=2) begin set @Index = ceiling(rand() * 52 + 10) end else if(@i=5) begin set @Index = ceiling(rand() * 20 + 62) end set @pwd = @pwd + substring(@strPwd,@Index,1) set @i = @i + 1 end set @i = 0 set @n = LEN(@pwd) while (@i < 6) begin set @Index = ceiling(rand() * @n) set @newPwd = @newPwd + substring(@pwd,@Index,1) set @pwd = STUFF(@pwd,@Index,1,'') set @n = @n-1 set @i = @i + 1 end select @newPwd
上述就是小编为大家分享的怎么在JS中以SQL方式随机生成高强度密码了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。