зеркало из https://github.com/mozilla/CSOL-site.git
Generating usernames and passwords
This commit is contained in:
Родитель
11eabf52e2
Коммит
db756c659b
|
@ -0,0 +1,20 @@
|
|||
var dictionary = require('./dictionary');
|
||||
|
||||
var adjectives = dictionary.adjectives;
|
||||
var nouns = dictionary.nouns;
|
||||
|
||||
function random (limit) {
|
||||
return Math.floor(Math.random() * limit);
|
||||
}
|
||||
|
||||
exports.generate = function generatePassword () {
|
||||
return (adjectives.random() + ' ' + nouns.random() + (10+random(89)))
|
||||
.toLowerCase()
|
||||
.replace(/(^|\W)(\w)/g, function(match, lead, character) { return lead + character.toUpperCase(); })
|
||||
.replace(/\W/, '');
|
||||
}
|
||||
|
||||
exports.validate = function validatePassword (password) {
|
||||
// TODO - make sure password is valid
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
var dictionary = require('./dictionary');
|
||||
|
||||
var adjectives = dictionary.adjectives;
|
||||
var nouns = dictionary.nouns;
|
||||
|
||||
exports.generate = function generateUsername () {
|
||||
return (adjectives.random() + ' ' + nouns.random())
|
||||
.toLowerCase()
|
||||
.replace(/(^| )(\w)/g, function(match, lead, character) { return lead + character.toUpperCase(); });
|
||||
}
|
||||
|
||||
exports.validate = function validateUsername (username) {
|
||||
// TODO - make sure username is valid
|
||||
if (username.length < 5)
|
||||
return false;
|
||||
return true;
|
||||
}
|
Загрузка…
Ссылка в новой задаче