From 56a7c49cbc9ae81b74b265a070a01a75310d23ef Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 24 Mar 2015 05:36:14 -0400 Subject: [PATCH] refactor(auth) init: add algo --- lib/server/auth.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/server/auth.js b/lib/server/auth.js index da052d51..c2dd9065 100644 --- a/lib/server/auth.js +++ b/lib/server/auth.js @@ -32,11 +32,11 @@ var auth = httpAuth.basic({ realm: 'Cloud Commander' }, function (username, password, callback) { - var hash, + var hash, sha, name = config('username'), pass = config('password'), equal = username === name, - sha = crypto.createHash('sha512WithRSAEncryption'); + algo = 'sha512WithRSAEncryption'; if (!oldPass) oldPass = pass; @@ -47,13 +47,14 @@ if (!equal) username === oldName; + sha = crypto.createHash(algo); sha.update(password); hash = sha.digest('hex'); equal = pass === hash && equal; if (!equal) { - sha = crypto.createHash('sha512WithRSAEncryption'); + sha = crypto.createHash(algo); sha.update(oldPass); hash = sha.digest('hex'); equal = pass === hash && equal;