<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script>
以下是我的比较密码=
的代码encrypt: function(values, callback) {
const saltRounds = 10;
var salt = bcrypt.genSaltSync(saltRounds);
var hash = bcrypt.hashSync(values.pass, salt);
bcrypt.compare(values.pass, hash, function(err, match) {
console.log('cocok encrypt ?', match);
});
values[tab.user.f.password] = "'"+hash+"'";
delete values.pass;
callback(null,values); },
插入数据库时,这是我的控制台日志(查询):
bcrypt.compare(password, user.password, function(err, match) {
if (err) return res.json(403, {err: 'forbidden'});
if (match) {
query=format("select {role} as role_id from {table} where {username}='"+ email +"'",
{table:tabuser.name,
username:tabuser.f.username,
role:tabuser.f.role});
ora.runQuery(query,function(err,cb) {
roleuser=cb[0];
console.log(user.username, err,roleuser,user);
if (err||!roleuser){
return res.json(403, {err: 'forbidden, no user role.'});
}else{
user['role_id']=roleuser.role_id;
res.json({user: user, token: sailsTokenAuth.issueToken({sid: user.username,sroleid:roleuser['role_id']})});
}
});
} else {
console.log("not match", match);
return res.json(401, {err: 'invalid password'});
};
});
这是我的比较控制台=
insert into AHMSDICC_MSTUSERS (vusername,vfullname,vemail,vphone,vaddress,vparen
t,vmdid,iroleid,vpass,dcrea,dmodi,vcrea,vmodi) VALUES ('ahm2','ahm2','ahm2','394
834','a','andi@mail','I01','1','$2a$10$5R27vVmSdkf/D3X0AuMTne5x/suiTiWW6LF2f9ZEz
eW4FZ7.8bBom',TO_DATE('07/03/2017 08:33:36','dd/mm/yyyy HH24:mi:ss'),TO_DATE('07
/03/2017 08:33:36','dd/mm/yyyy HH24:mi:ss'),'admin','admin')
但结果总是不匹配,因为我使用oracledb进行插入和获取查询的信息