Skip to content

Commit

Permalink
Hash password on client side
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-WWU-IT committed Aug 2, 2021
1 parent f5c4819 commit 66b146b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
29 changes: 16 additions & 13 deletions pkg/siteacc/account/edit/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,22 @@ function handleAction(action) {
}
}
var postData = {
"firstName": formData.getTrimmed("fname"),
"lastName": formData.getTrimmed("lname"),
"organization": formData.getTrimmed("organization"),
"website": formData.getTrimmed("website"),
"role": formData.getTrimmed("role"),
"phoneNumber": formData.getTrimmed("phone"),
"password": {
"value": formData.get("password")
}
};
xhr.send(JSON.stringify(postData));
var pwd = formData.get("password");
pwd.hashCode().then(function(pwdHash) {
var postData = {
"firstName": formData.getTrimmed("fname"),
"lastName": formData.getTrimmed("lname"),
"organization": formData.getTrimmed("organization"),
"website": formData.getTrimmed("website"),
"role": formData.getTrimmed("role"),
"phoneNumber": formData.getTrimmed("phone"),
"password": {
"value": pwdHash
}
};
xhr.send(JSON.stringify(postData));
});
}
`

Expand Down
19 changes: 11 additions & 8 deletions pkg/siteacc/account/login/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,17 @@ function handleAction(action) {
}
}
var postData = {
"email": formData.getTrimmed("email"),
"password": {
"value": formData.get("password")
}
};
xhr.send(JSON.stringify(postData));
var pwd = formData.get("password");
pwd.hashCode().then(function(pwdHash) {
var postData = {
"email": formData.getTrimmed("email"),
"password": {
"value": pwdHash
}
};
xhr.send(JSON.stringify(postData));
});
}
function handleResetPassword() {
Expand Down
11 changes: 11 additions & 0 deletions pkg/siteacc/html/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ const panelTemplate = `
}
}
String.prototype.hashCode = async function() {
if (this.length === 0) {
return "";
}
var msgBuffer = new TextEncoder().encode(this);
var hashBuffer = await crypto.subtle.digest("SHA-256", msgBuffer);
var hashArray = Array.from(new Uint8Array(hashBuffer));
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
};
$(CONTENT_JAVASCRIPT)
</script>
<style>
Expand Down

0 comments on commit 66b146b

Please sign in to comment.