hashing password

This commit is contained in:
wt committed 2024-12-04 10:14:10 +07:00
1 parent 1d7b443697
commit 5432e18a77
2 files changed
+13 -2

No files matched your search

+12 -1
View File
@@ -11,9 +11,20 @@ if (localStorage.getItem("token") === null) {
loginformbody.addEventListener('submit', (e) => {
e.preventDefault()
login(loginforminputusername.value, loginforminputpassword.value)
hashPassword(loginforminputpassword.value).then(hashedpassword => {
login(loginforminputusername.value, hashedpassword)
})
})
const hashPassword = async (password) => {
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
}
const login = async (username, password) => {
const response = await fetch(routes.login(), {
method: 'POST',