Share `randomString` method.
This simply shares a common implementation and makes no judgements on the validity of its use. The string created is not a secure random number, so some uses of it may not be applicable.pull/352/head
parent
34edba3adf
commit
363e168561
|
@ -5,7 +5,7 @@ var ueberDB = require("ueberDB");
|
|||
var mysql = require("mysql");
|
||||
var async = require("async");
|
||||
var Changeset = CommonCode.require("/Changeset");
|
||||
var randomString = require("../node/utils/randomstring");
|
||||
var randomString = CommonCode.require('/pad_utils').randomString;
|
||||
var AttributePoolFactory = CommonCode.require("/AttributePoolFactory");
|
||||
|
||||
var settingsFile = process.argv[2];
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var CommonCode = require('../utils/common_code');
|
||||
var ERR = require("async-stacktrace");
|
||||
var db = require("./DB").db;
|
||||
var async = require("async");
|
||||
|
||||
var randomString = require("../utils/randomstring");
|
||||
var randomString = CommonCode.require('/pad_utils').randomString;
|
||||
|
||||
/**
|
||||
* Checks if the author exists
|
||||
|
|
|
@ -18,9 +18,10 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var CommonCode = require('../utils/common_code');
|
||||
var ERR = require("async-stacktrace");
|
||||
var customError = require("../utils/customError");
|
||||
var randomString = require("../utils/randomstring");
|
||||
var randomString = CommonCode.require('/pad_utils').randomString;
|
||||
var db = require("./DB").db;
|
||||
var async = require("async");
|
||||
var padManager = require("./PadManager");
|
||||
|
|
|
@ -6,6 +6,7 @@ var CommonCode = require('../utils/common_code');
|
|||
var ERR = require("async-stacktrace");
|
||||
var Changeset = CommonCode.require("/Changeset");
|
||||
var AttributePoolFactory = CommonCode.require("/AttributePoolFactory");
|
||||
var randomString = CommonCode.require('/pad_utils').randomString;
|
||||
var db = require("./DB").db;
|
||||
var async = require("async");
|
||||
var settings = require('../utils/Settings');
|
||||
|
@ -478,15 +479,7 @@ function hash(password, salt)
|
|||
|
||||
function generateSalt()
|
||||
{
|
||||
var len = 86;
|
||||
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz./";
|
||||
var randomstring = '';
|
||||
for (var i = 0; i < len; i++)
|
||||
{
|
||||
var rnum = Math.floor(Math.random() * chars.length);
|
||||
randomstring += chars.substring(rnum, rnum + 1);
|
||||
}
|
||||
return randomstring;
|
||||
return randomstring(86);
|
||||
}
|
||||
|
||||
function compare(hashStr, password)
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var CommonCode = require('../utils/common_code');
|
||||
var ERR = require("async-stacktrace");
|
||||
var db = require("./DB").db;
|
||||
var async = require("async");
|
||||
|
||||
var randomString = require("../utils/randomstring");
|
||||
var randomString = CommonCode.require('/pad_utils').randomString;
|
||||
|
||||
/**
|
||||
* returns a read only id for a pad
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var CommonCode = require('../utils/common_code');
|
||||
var ERR = require("async-stacktrace");
|
||||
var db = require("./DB").db;
|
||||
var async = require("async");
|
||||
|
@ -25,8 +26,7 @@ var authorManager = require("./AuthorManager");
|
|||
var padManager = require("./PadManager");
|
||||
var sessionManager = require("./SessionManager");
|
||||
var settings = require("../utils/Settings")
|
||||
|
||||
var randomString = require("../utils/randomstring");
|
||||
var randomString = CommonCode.require('/pad_utils').randomString;
|
||||
|
||||
/**
|
||||
* This function controlls the access to a pad, it checks if the user can access a pad.
|
||||
|
|
|
@ -18,9 +18,10 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var CommonCode = require('../utils/common_code');
|
||||
var ERR = require("async-stacktrace");
|
||||
var customError = require("../utils/customError");
|
||||
var randomString = require("../utils/randomstring");
|
||||
var randomString = CommonCode.require('/pad_utils').randomString;
|
||||
var db = require("./DB").db;
|
||||
var async = require("async");
|
||||
var groupMangager = require("./GroupManager");
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var CommonCode = require('../utils/common_code');
|
||||
var ERR = require("async-stacktrace");
|
||||
var fs = require("fs");
|
||||
var api = require("../db/API");
|
||||
var padManager = require("../db/PadManager");
|
||||
var randomString = require("../utils/randomstring");
|
||||
var randomString = CommonCode.require('/pad_utils').randomString;
|
||||
|
||||
//ensure we have an apikey
|
||||
var apikey = null;
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
/**
|
||||
* Generates a random String with the given length. Is needed to generate the Author, Group, readonly, session Ids
|
||||
*/
|
||||
var randomString = function randomString(len)
|
||||
{
|
||||
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
var randomstring = '';
|
||||
for (var i = 0; i < len; i++)
|
||||
{
|
||||
var rnum = Math.floor(Math.random() * chars.length);
|
||||
randomstring += chars.substring(rnum, rnum + 1);
|
||||
}
|
||||
return randomstring;
|
||||
};
|
||||
|
||||
module.exports = randomString;
|
|
@ -48,19 +48,7 @@ var padutils = require('/pad_utils').padutils;
|
|||
|
||||
var createCookie = require('/pad_utils').createCookie;
|
||||
var readCookie = require('/pad_utils').readCookie;
|
||||
|
||||
function randomString()
|
||||
{
|
||||
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
var string_length = 20;
|
||||
var randomstring = '';
|
||||
for (var i = 0; i < string_length; i++)
|
||||
{
|
||||
var rnum = Math.floor(Math.random() * chars.length);
|
||||
randomstring += chars.substring(rnum, rnum + 1);
|
||||
}
|
||||
return "t." + randomstring;
|
||||
}
|
||||
var randomString = require('/pad_utils').randomString;
|
||||
|
||||
function getParams()
|
||||
{
|
||||
|
@ -184,7 +172,7 @@ function handshake()
|
|||
var token = readCookie("token");
|
||||
if (token == null)
|
||||
{
|
||||
token = randomString();
|
||||
token = "t." + randomString();
|
||||
createCookie("token", token, 60);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,23 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Generates a random String with the given length. Is needed to generate the Author, Group, readonly, session Ids
|
||||
*/
|
||||
|
||||
function randomString(len)
|
||||
{
|
||||
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
var randomstring = '';
|
||||
len = len || 20
|
||||
for (var i = 0; i < len; i++)
|
||||
{
|
||||
var rnum = Math.floor(Math.random() * chars.length);
|
||||
randomstring += chars.substring(rnum, rnum + 1);
|
||||
}
|
||||
return randomstring;
|
||||
}
|
||||
|
||||
function createCookie(name, value, days, path)
|
||||
{
|
||||
if (days)
|
||||
|
@ -510,6 +527,7 @@ padutils.setupGlobalExceptionHandler = setupGlobalExceptionHandler;
|
|||
|
||||
padutils.binarySearch = require('/ace2_common').binarySearch;
|
||||
|
||||
exports.randomString = randomString;
|
||||
exports.createCookie = createCookie;
|
||||
exports.readCookie = readCookie;
|
||||
exports.padutils = padutils;
|
||||
|
|
|
@ -28,17 +28,7 @@ require('/undo-xpopup');
|
|||
|
||||
var createCookie = require('/pad_utils').createCookie;
|
||||
var readCookie = require('/pad_utils').readCookie;
|
||||
|
||||
function randomString() {
|
||||
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
var string_length = 20;
|
||||
var randomstring = '';
|
||||
for (var i=0; i<string_length; i++) {
|
||||
var rnum = Math.floor(Math.random() * chars.length);
|
||||
randomstring += chars.substring(rnum,rnum+1);
|
||||
}
|
||||
return "t." + randomstring;
|
||||
}
|
||||
var randomString = require('/pad_utils').randomString;
|
||||
|
||||
var socket, token, padId, export_links;
|
||||
|
||||
|
@ -59,7 +49,7 @@ function init() {
|
|||
token = readCookie("token");
|
||||
if(token == null)
|
||||
{
|
||||
token = randomString();
|
||||
token = "t." + randomString();
|
||||
createCookie("token", token, 60);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue