Last active
October 6, 2016 17:13
-
-
Save juanmaguitar/4334ff682822341c1e4339f934cd36f3 to your computer and use it in GitHub Desktop.
User password genrerated
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function User ( name, username ) { | |
var password = User.generatePassword(15); | |
this.name = name; | |
this.username = username; | |
this.password = User.encryptPassword( password ); | |
console.log("Your password is : " + password) | |
} | |
User.randomChar = function() { | |
var chars = "abcdefghijklmnopqrstxyz"; | |
var numChars = chars.length; | |
var randomCharPos = Math.round(Math.random()*numChars) | |
return chars[randomCharPos]; | |
} | |
User.generatePassword = function( passwordLentgth ) { | |
return Array(passwordLentgth) | |
.fill(0) | |
.map( function() { | |
return User.randomChar() | |
}) | |
.join("") | |
} | |
User.encryptPassword = function( password ) { | |
var codes = { a: "4", e: "3", i: "1", o: "0", u: "2" } | |
return password | |
.split("") | |
.map( function(elem) { | |
return codes[elem] || elem; | |
}) | |
.join(""); | |
} | |
User.prototype.decryptPassword = function() { | |
var codes = ["o","i","u","e","a"] | |
return this.password | |
.split("") | |
.map( function(elem) { | |
return codes[elem] || elem; | |
}).join(""); | |
} | |
var me = new User("JuanMa", "juanmaguitar") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment