Due to security needs, it is recommended that users use different strong passwords on different websites. Setting a strong password every time can be troublesome, so here we write a small Python program to generate strong passwords. In the future, just visit the following website and copy-paste the password.
Python code as follows
import random
def get_strong_pass():
strongpassword=""
for i in range(16):
strongpassword += random.choice('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_')
return strongpassword
get_strong_pass()
Next, just call this function inside Django. Here I integrated the code into WordPress, so when visiting this page, you can see the just-generated strong password at the bottom.
JavaScript code
<script>
function createPassword(min,max) {
// Arrays used for generating random passwords
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);
// Ensure at least one from each group exists
var arr = [];
arr.push(getOne(num));
arr.push(getOne(english));
arr.push(getOne(ENGLISH));
arr.push(getOne(special));
// Get the desired password length
var len = min + Math.floor(Math.random()*(max-min+1));
for(var i=4; i<len; i++){
// Pick a random character from the config array
arr.push(config[Math.floor(Math.random()*config.length)]);
}
// Shuffle the array
var newArr = [];
for(var j=0; j<len; j++){
newArr.push(arr.splice(Math.random()*arr.length,1)[0]);
}
// Randomly pick one value from an array
function getOne(arr) {
return arr[Math.floor(Math.random()*arr.length)];
}
return newArr.join("");
}
document.write(createPassword(15,15));
</script>