Add 卓米会 mini program and admin server.
Initial commit of the WeChat mini program, Express backend, and admin console. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
const crypto = require('crypto')
|
||||
|
||||
const PREFIX = 'scrypt$'
|
||||
|
||||
function hash(plain) {
|
||||
const salt = crypto.randomBytes(16).toString('hex')
|
||||
const digest = crypto.scryptSync(String(plain), salt, 32).toString('hex')
|
||||
return `${PREFIX}${salt}$${digest}`
|
||||
}
|
||||
|
||||
function isHashed(stored) {
|
||||
return typeof stored === 'string' && stored.startsWith(PREFIX)
|
||||
}
|
||||
|
||||
function verify(plain, stored) {
|
||||
if (!isHashed(stored)) return false
|
||||
const parts = stored.split('$')
|
||||
const expected = Buffer.from(parts[2], 'hex')
|
||||
const actual = crypto.scryptSync(String(plain), parts[1], expected.length)
|
||||
return crypto.timingSafeEqual(expected, actual)
|
||||
}
|
||||
|
||||
module.exports = { hash, verify, isHashed }
|
||||
Reference in New Issue
Block a user