我对 Loopback 非常陌生,我想将 Loopback 的默认密码哈希方法覆盖为当前在我的后端使用的方法,以便我可以将此应用程序与该数据库同步。
我读了这个链接https://groups.google.com/forum/#!topic/loopbackjs/ROv5nQAcNfM https://groups.google.com/forum/#!topic/loopbackjs/ROv5nQAcNfM但我无法理解如何覆盖密码和验证?
您可以覆盖User.hashPassword
实现您自己的哈希方法。
假设您有一个模型 Customer,它以 User 作为基本模型,
在 customer.js 中,您可以添加以下代码片段,
Customer.hashPassword = function(plain) {
this.validatePassword(plain);
return plain + '1'; // your hashing algo will come here.
};
这会将 1 附加到所有密码。
现在你需要重写另一个函数User.prototype.hasPassword
它将用户输入的密码与哈希密码相匹配,
Customer.prototype.hasPassword = function(plain, fn) {
fn = fn || utils.createPromiseCallback();
if (this.password && plain) {
const isMatch = this.password === plain + '1' // same hashing algo to come here.
fn(null, isMatch)
} else {
fn(null, false);
}
return fn.promise;
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)