mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	
		
			
	
	
		
			28 lines
		
	
	
		
			632 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
		
		
			
		
	
	
			28 lines
		
	
	
		
			632 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
|  | const sql = require('./sql'); | ||
|  | const scrypt = require('scrypt'); | ||
|  | 
 | ||
|  | async function getVerificationHash(password) { | ||
|  |     const salt = await sql.getOption('password_verification_salt'); | ||
|  | 
 | ||
|  |     return getScryptHash(password, salt); | ||
|  | } | ||
|  | 
 | ||
|  | async function getPasswordDerivedKey(password) { | ||
|  |     const salt = await sql.getOption('password_derived_key_salt'); | ||
|  | 
 | ||
|  |     return getScryptHash(password, salt); | ||
|  | } | ||
|  | 
 | ||
|  | async function getScryptHash(password, salt) { | ||
|  |     const hashed = scrypt.hashSync(password, | ||
|  |         {N: 16384, r:8, p:1}, | ||
|  |         32, | ||
|  |         salt); | ||
|  | 
 | ||
|  |     return hashed; | ||
|  | } | ||
|  | 
 | ||
|  | module.exports = { | ||
|  |     getVerificationHash, | ||
|  |     getPasswordDerivedKey | ||
|  | }; |