Generating usernames and passwords

This commit is contained in:
Andrew Hayward 2013-05-16 08:28:37 +01:00
Родитель 11eabf52e2
Коммит db756c659b
2 изменённых файлов: 37 добавлений и 0 удалений

20
lib/passwords.js Normal file
Просмотреть файл

@ -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;
}

17
lib/usernames.js Normal file
Просмотреть файл

@ -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;
}