From 45b6f32943a816a687f3493fe2a246830d1e08d0 Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Tue, 14 May 2013 09:47:53 +0200 Subject: added length parameter to random token generator --- models/User.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'models/User.js') diff --git a/models/User.js b/models/User.js index 9e6e52f..a40ba34 100644 --- a/models/User.js +++ b/models/User.js @@ -29,7 +29,8 @@ var UserSchema = new Schema({ accessToken: String, facebook: {}, twitter: {}, - status: { type: Number, default: 2 } + status: { type: Number, default: 2 }, + randomToken: String }); @@ -140,14 +141,16 @@ UserSchema.methods = { /** * Generate random access token for Remember Me function * + * @param {Number} length * @return {String} * @api public */ - generateRandomToken: function() { + generateRandomToken: function(length) { + if (typeof(length) === 'undefined') length = 16; // default length of token var chars = "_!abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" , token = new Date().getTime() + '_'; - for (var i = 0; i < 16; i++) { + for (var i = 0; i < length; i++) { var x = Math.floor(Math.random() * 62); token += chars.charAt(x); } -- cgit v1.2.3