Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function passwordMD5(str, key){
// shaObj 对象存有多种SHA加密值: SHA-512 SHA-1 SHA-224, SHA-256, SHA-384
var strMd5 = utility.md5(str);
//console.log('strMd5:'+strMd5);
var shaObj = new jsSHA(strMd5, 'TEXT');
//console.log("SHA-1 : "+shaObj.getHash('SHA-1', 'HEX'));
return '' === str ? '' : utility.md5(shaObj.getHash('SHA-1', 'HEX') + key);
}
// HA2 = MD5( "GET:/dir/index.html" )
// = 39aff3a2bab6126f332b942af96d3366
//
// Response = MD5( "939e7578ed9e3c518a452acee763bce9:\
// dcd98b7102dd2f0e8b11d0f600bfb0c093:\
// 00000001:0a4f113b:auth:\
// 39aff3a2bab6126f332b942af96d3366" )
// = 6629fae49393a05397450978507c4ef1
userpass = userpass.split(':');
var nc = String(++NC);
nc = NC_PAD.substring(nc.length) + nc;
var cnonce = crypto.randomBytes(8).toString('hex');
var ha1 = utility.md5(userpass[0] + ':' + opts.realm + ':' + userpass[1]);
var ha2 = utility.md5(method.toUpperCase() + ':' + uri);
var s = ha1 + ':' + opts.nonce;
if (qop) {
qop = qop.split(',')[0];
s += ':' + nc + ':' + cnonce + ':' + qop;
}
s += ':' + ha2;
var response = utility.md5(s);
var authstring = 'Digest username="' + userpass[0] + '", realm="' + opts.realm
+ '", nonce="' + opts.nonce + '", uri="' + uri
+ '", response="' + response + '"';
if (opts.opaque) {
authstring += ', opaque="' + opts.opaque + '"';
}
if (qop) {
authstring += ', qop=' + qop + ', nc=' + nc + ', cnonce="' + cnonce + '"';
}
if (pwd1 !== pwd) {
return res.json({
code: 0,
msg: 'error'
});
}
}
// console.log('密码校验结束', pwd, pwd1, pwd2, pwd3);
// 为了实现修改密码和会员中心修改的同步性,使用这个变量用来区分会员中心和修改密码这两个模块的信息修改
if (pwd3) {
// console.log('我是要开始修改密码了');
// 开始修改密码
pwd2 = utility.md5(pwd2);
// 对密码进行再次加密
pwd = utility.md5(pwd2 + req.app.locals.config.secretKey);
}
let user = new User({
id,
uname,
pwd,
email,
phone,
info,
face
});
// console.log(user, req.session.user.id);
user.update(function (err, result) {
// console.log(result);
handleSubmit() {
const { submitState, setSubmitState, update, id } = this.props;
if(submitState == SUBMITSTATES.SUBMITTING) {
return;
}
setSubmitState(SUBMITSTATES.SUBMITTING);
const backupConfig = object.clone(this.props.backupConfig);
for(const key in backupConfig) {
if(input.isEmpty(backupConfig[key])) {
delete backupConfig[key];
continue;
}
if(key == "duration" || key == "interval") {
backupConfig[key] = time.convertToMilliseconds(backupConfig[key]);
}
}
if(!update) {
//create a new backup
backups.newBackupConfig(backupConfig)
.then(response => {
this.submitErr = response.data.message;
// redirect to the main page
hashHistory.push('/');
})
const onError = err => {
console.error('%s ERROR %s [egg-logger] [%s] %s',
utility.logDate(','), process.pid, this.options.file, err.stack);
this.reload();
console.warn('%s WARN %s [egg-logger] [%s] reloaded', utility.logDate(','), process.pid, this.options.file);
};
// only listen error once because stream will reload after error
const onError = err => {
console.error(
'%s ERROR %s [logger] [%s] %s',
utility.logDate(','),
process.pid,
filename,
err.stack
);
this.reload();
console.warn(
'%s WARN %s [logger] [%s] reloaded',
utility.logDate(','),
process.pid,
filename
);
};
// only listen error once because stream will reload after error
await this.snapshot.delete(key);
err.name = 'ServerListSnapShotJSONParseError';
err.unit = unit;
err.data = data;
this.emit('error', err);
}
}
}
if (!hosts || !hosts.length) {
// 这里主要是为了让后面定时同步可以执行
this.serverListCache.set(unit, null);
return null;
}
const serverData = {
hosts,
index: random(hosts.length),
};
this.serverListCache.set(unit, serverData);
return serverData;
}
await this.snapshot.delete(key);
err.name = 'ServerListSnapShotJSONParseError';
err.unit = unit;
err.data = data;
this.emit('error', err);
}
}
}
if (!hosts || !hosts.length) {
// 这里主要是为了让后面定时同步可以执行
this.serverListCache.set(unit, null);
return null;
}
const serverData = {
hosts,
index: random(hosts.length),
};
this.serverListCache.set(unit, serverData);
return serverData;
}
handleSubmit() {
const { submitState, setSubmitState, update, id } = this.props;
if(submitState == SUBMITSTATES.SUBMITTING) {
return;
}
setSubmitState(SUBMITSTATES.SUBMITTING);
const backupConfig = object.clone(this.props.backupConfig);
for(const key in backupConfig) {
if(input.isEmpty(backupConfig[key])) {
delete backupConfig[key];
continue;
}
if(key == "duration" || key == "interval") {
backupConfig[key] = time.convertToMilliseconds(backupConfig[key]);
}
}
if(!update) {
//create a new backup
backups.newBackupConfig(backupConfig)
.then(response => {
this.submitErr = response.data.message;
// redirect to the main page
UserSchema.virtual('avatar_url').get(function () {
var url = this.avatar || ('//gravatar.com/avatar/' + utility.md5(this.email.toLowerCase()) + '?size=48');
// www.gravatar.com 被墙
url = url.replace('//www.gravatar.com', '//gravatar.com');
// 让协议自适应 protocol
if (url.indexOf('http:') === 0) {
url = url.slice(5);
}
// 如果是 github 的头像,则限制大小
if (url.indexOf('githubusercontent') !== -1) {
url += '&s=120';
}
return url;
});