python随机生成强密码
由于安全需要,建议网友们在不同的网站上都使用不同的强密码,那么每次设置一个强密码还是比较麻烦的,这里我们写一个使用python生成强密码的小程序。以后要用的话直接访问以下网站把密码复制粘贴过来就好了。
python代码如下
import random
def get_strong_pass():
strongpassword=""
for i in range(16):
strongpassword += random.choice('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_')
return strongpassword
get_strong_pass()
接下来把函数放在django里面调用就可以了。这里我把代码整合到了wordpress里面,在访问此页面的时候就可以在最下方看到刚生成的强密码。
javascript 代码
<script>
function createPassword(min,max) {
//可以生成随机密码的相关数组
var num = ["0","1","2","3","4","5","6","7","8","9"];
var english = ["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 ENGLISH = ["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 special = ["-","_","#"];
var config = num.concat(english).concat(ENGLISH).concat(special);
//先放入一个必须存在的
var arr = [];
arr.push(getOne(num));
arr.push(getOne(english));
arr.push(getOne(ENGLISH));
arr.push(getOne(special));
//获取需要生成的长度
var len = min + Math.floor(Math.random()*(max-min+1));
for(var i=4; i<len; i++){
//从数组里面抽出一个
arr.push(config[Math.floor(Math.random()*config.length)]);
}
//乱序
var newArr = [];
for(var j=0; j<len; j++){
newArr.push(arr.splice(Math.random()*arr.length,1)[0]);
}
//随机从数组中抽出一个数值
function getOne(arr) {
return arr[Math.floor(Math.random()*arr.length)];
}
return newArr.join("");
}
document.write(createPassword(15,15));
</script>
强密码在这里
- 原文作者:春江暮客
- 原文链接:https://www.bobobk.com/136.html
- 版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。