mirror of
				https://github.com/louislam/uptime-kuma.git
				synced 2025-11-04 13:46:13 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			24 lines
		
	
	
		
			542 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
		
			542 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
const passwordHashOld = require("password-hash");
 | 
						|
const bcrypt = require("bcryptjs");
 | 
						|
const saltRounds = 10;
 | 
						|
 | 
						|
exports.generate = function (password) {
 | 
						|
    return bcrypt.hashSync(password, saltRounds);
 | 
						|
}
 | 
						|
 | 
						|
exports.verify = function (password, hash) {
 | 
						|
    if (isSHA1(hash)) {
 | 
						|
        return passwordHashOld.verify(password, hash)
 | 
						|
    }
 | 
						|
 | 
						|
    return bcrypt.compareSync(password, hash);
 | 
						|
}
 | 
						|
 | 
						|
function isSHA1(hash) {
 | 
						|
    return (typeof hash === "string" && hash.startsWith("sha1"))
 | 
						|
}
 | 
						|
 | 
						|
exports.needRehash = function (hash) {
 | 
						|
    return isSHA1(hash);
 | 
						|
}
 |