Authored by 王水玲

uid cookie 加密解密

... ... @@ -32,16 +32,18 @@ passport.use(new LocalStrategy({
passwordField: 'password',
passReqToCallback: true
}, (req, username, password, done) => {
let area = req.body.area || '86';
let area = req.body.areaCode || '86';
if (isNaN(parseInt(area, 0)) || _.isEmpty(username) || _.isEmpty(password)) {
logger.info(`【Passport Loginbad params, area:${area} account:${username} password:${password}`);
return done('登录参数错误', null);
}
let verifyEmail = helpers.verifyEmail(username);
let verifyMobile = helpers.verifyAreaMobile(username, area);
// 国际号码验证取消
let verifyMobile = area === '86' ? helpers.verifyAreaMobile(area + '-' + username) : true;
if (!verifyEmail && !verifyMobile) {
logger.info(`【Passport Loginbad account, email:${verifyEmail} mobile:${verifyMobile}`);
... ... @@ -56,7 +58,7 @@ passport.use(new LocalStrategy({
let shoppingKey = cookie.getShoppingKey(req);
AuthHelper.signinAes(area, username, password, shoppingKey).then((result) => {
AuthHelper.signin(area, username, password, shoppingKey).then((result) => {
if (result.code && result.code === 200 && result.data.uid) {
done(null, result.data);
} else {
... ...
/**
* 登录注册密码加密
* 登录注册密码加密,uid加密
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/07/07
*/
... ... @@ -8,21 +8,63 @@
const crypto = require('crypto');
const aesPwd = (pwd) => {
let algorithm = 'aes-128-ecb';
let key = 'yoho9646yoho9646';
let clearEncoding = 'utf8';
let cipherEncoding = 'base64';
let iv = '';
const algorithm = 'aes-128-ecb';
const clearEncoding = 'utf8';
const cipherEncoding = 'base64';
const iv = '';
// 加密
const _encryption = (keys, Keyword) => {
let key = keys ? keys : 'yoho9646abcdefgh';
let cipher = crypto.createCipheriv(algorithm, key, iv);
let cipherChunks = [];
cipherChunks.push(cipher.update(pwd, clearEncoding, cipherEncoding));
cipherChunks.push(cipher.update(Keyword, clearEncoding, cipherEncoding));
cipherChunks.push(cipher.final(cipherEncoding));
return cipherChunks.join('');
}
//解密
const _decrypt = (keys, Keyword) => {
let key = keys ? keys : 'yoho9646abcdefgh';
let decipher = crypto.createDecipheriv(algorithm, key, iv);
let plainChunks = [];
let cipherChunks = [Keyword];
for (var i = 0; i < cipherChunks.length; i++) {
plainChunks.push(decipher.update(cipherChunks[i], cipherEncoding, clearEncoding));
}
plainChunks.push(decipher.final(clearEncoding));
return plainChunks.join('');
}
/**
* 登录密码加密
**/
const aesPwd = (pwd) => {
return _encryption('yoho9646yoho9646', pwd);
};
/**
* uid加密
**/
const encryptionUid = (uid) => {
return _encryption('yoho9646abcdefgh', uid + '');
};
/**
* uid解密
**/
const DecryptUid = (uid) => {
return _decrypt('yoho9646abcdefgh', uid + '');
};
module.exports = {
aesPwd
aesPwd,
encryptionUid,
DecryptUid
};
... ...
... ... @@ -64,9 +64,10 @@ class Auth {
return Auth.profile(uid).then((userInfo) => {
let token = sign.makeToken(uid);
let data = userInfo.data;
let encryptionUid = aes.encryptionUid(data.uid);
if (data) {
let uidCookie = `${data.profile_name}::${data.uid}::${data.vip_info.title}::${token}`;
let uidCookie = `${data.profile_name}::${encryptionUid}::${data.vip_info.title}::${token}`;
res.cookie('_UID', uidCookie, {
domain: 'yohobuy.com',
... ...