11 lines
465 B
JavaScript
11 lines
465 B
JavaScript
const hashPassword = async (password) => {
|
|
if (crypto && crypto.subtle) {
|
|
const encoder = new TextEncoder()
|
|
const data = encoder.encode(password)
|
|
const hashBuffer = await crypto.subtle.digest('SHA-256', data)
|
|
const hashArray = Array.from(new Uint8Array(hashBuffer))
|
|
const hashHex = hashArray.map(b=>('00' + b.toString(16)).slice(-2)).join('')
|
|
return hashHex
|
|
}
|
|
return CryptoJS.SHA256(password).toString()
|
|
} |