我需要使用以下命令生成密码:
~ ! @ # $ % ^ * ( ) _ +
?我使用了随意的lib,但是我无法生成特殊的角色。任何人都可以帮我解决这个问题吗?
var casual = require('casual');
var password = casual.password.substring(10,{
length: 10,
uppercase: true,
lowercase: true,
number: true,
symbols: true,
strict: true
});
答案 0 :(得分:3)
应该相当容易自己动手:
const lowercaseLetter = () => casual.random_element('ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''));
const uppercaseLetter = () => casual.random_element('abcdefghijklmnopqrstuvwxyz'.split(''));
const specialCharacter = () => casual.random_element('~!@#$%^*()_+'.split(''));
const anyCharacter = () => casual.random_element([lowercaseLetter(), uppercaseLetter(), specialCharacter()]);
casual.define('specialPassword', function() {
const length = casual.integer(from = 7, to = 15);
const pw = [lowercaseLetter(), uppercaseLetter(), specialCharacter()];
while (pw.length < length) {
pw.push(anyCharacter());
}
return pw.join('');
});
当然,如果你关心的话,你应该在最后一行洗牌pw
&#34;更安全&#34;密码。