hashing password
This commit is contained in:
+1
-1
@@ -36,7 +36,7 @@ void auth(const httplib::Request &request, httplib::Response &response) {
|
||||
|
||||
std::string userid;
|
||||
for (nlohmann::basic_json<> user: all_users) {
|
||||
if ((user["username"] == request_username) && (user["password"] == hashPassword(request_password))) {
|
||||
if ((user["username"] == request_username) && (user["password"] == request_password)) {
|
||||
userid = user["id"];
|
||||
break;
|
||||
}
|
||||
|
||||
+12
-1
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user