hashing password
This commit is contained in:
1 parent
5432e18a77
commit
c26cb038f7
6 files changed
+17
-12
No files matched your search
@@ -133,6 +133,7 @@
|
||||
<tbody class="alluserstablebody"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
<script src="js/security.js"></script>
|
||||
<script src="js/message.js"></script>
|
||||
<script src="js/routes.js"></script>
|
||||
<script src="js/window.js"></script>
|
||||
|
||||
@@ -18,9 +18,10 @@ canceladduserbutton.addEventListener('click', (e) => {
|
||||
|
||||
adduserformbody.addEventListener('submit', async (e) => {
|
||||
e.preventDefault()
|
||||
const hashedpassword = await hashPassword(passwordinput.value)
|
||||
const new_user = {
|
||||
username: usernameinput.value,
|
||||
password: passwordinput.value,
|
||||
password: hashedpassword,
|
||||
group: groupinput.value,
|
||||
is_superuser: is_superuserinput.checked?"1":"0"
|
||||
}
|
||||
|
||||
@@ -17,9 +17,10 @@ cancelchangepassword.addEventListener('click', e => {
|
||||
|
||||
changepasswordformbody.addEventListener('submit', async e => {
|
||||
e.preventDefault()
|
||||
const hashedpassword = await hashPassword(changepasswordnewpassword.value)
|
||||
const status = await fetch(routes.change_password_url(), {
|
||||
method: 'POST',
|
||||
body: `{"token":"${localStorage.getItem('token')}","userid":"${changepassuserid}","new_password":"${changepasswordnewpassword.value}"}`
|
||||
body: `{"token":"${localStorage.getItem('token')}","userid":"${changepassuserid}","new_password":"${hashedpassword}"}`
|
||||
}).then(data => data.json()).then(jsondata => jsondata).catch((error) => {
|
||||
notification(`Ошибка на сервере: ${error}`, "error")
|
||||
})
|
||||
|
||||
@@ -38,7 +38,10 @@ changeuserformbody.addEventListener('submit', async (e) => {
|
||||
is_superuser: changeuserformissuperuser.checked ? "1" : "0",
|
||||
group: changeuserformgroup.value
|
||||
};
|
||||
if (changeuserformpassword.value !== "") {request = {...request, "password": changeuserformpassword.value}}
|
||||
if (changeuserformpassword.value !== "") {
|
||||
const hashedpassword = await hashPassword(changeuserformpassword.value)
|
||||
request = {...request, "password": hashedpassword}
|
||||
}
|
||||
const status = await fetch(routes.change_user(), {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(request)
|
||||
|
||||
@@ -16,15 +16,6 @@ loginformbody.addEventListener('submit', (e) => {
|
||||
})
|
||||
})
|
||||
|
||||
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',
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
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
|
||||
}
|
||||
Reference in new issue
Block a user