sha256 passwords client-side before sending (why didn't I do this before?)

This commit is contained in:
jvyden 2021-11-20 02:21:42 -05:00
commit f005aca48c
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
4 changed files with 40 additions and 9 deletions

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptLibraryMappings">
<file url="PROJECT" libraries="{sha256}" />
</component>
</project>

View file

@ -4,8 +4,21 @@
@{
Layout = "Layouts/BaseLayout";
}
<script src="https://geraintluff.github.io/sha256/sha256.min.js"></script>
<script>
function onSubmit(form) {
const password = form['password'];
password.value = sha256(password.value);
return true;
}
</script>
<h1>Log in</h1>
<form>
<form onsubmit="return onSubmit(this)">
<label for="text">Username: </label>
<input type="text" name="username" id="text"><br>

View file

@ -5,8 +5,23 @@
Layout = "Layouts/BaseLayout";
}
<script src="https://geraintluff.github.io/sha256/sha256.min.js"></script>
<script>
function onSubmit(form) {
const password = form['password'];
const confirmPassword = form['confirmPassword'];
password.value = sha256(password.value);
confirmPassword.value = sha256(confirmPassword.value);
return true;
}
</script>
<h1>Register</h1>
<form>
<form onsubmit="return onSubmit(this)">
<label for="text">Username: </label>
<input type="text" name="username" id="text"><br>

View file

@ -1,4 +1,3 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using JetBrains.Annotations;
@ -20,18 +19,16 @@ namespace LBPUnion.ProjectLighthouse.Pages.ExternalAuth
[SuppressMessage("ReSharper", "SpecifyStringComparison")]
public async Task<IActionResult> OnGet([FromQuery] string username, [FromQuery] string password, [FromQuery] string confirmPassword)
{
this.WasRegisterRequest = !string.IsNullOrEmpty(username) &&
!string.IsNullOrEmpty(password) &&
!string.IsNullOrEmpty(confirmPassword) &&
password == confirmPassword;
this.WasRegisterRequest = !string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password) && !string.IsNullOrEmpty(confirmPassword);
if (WasRegisterRequest)
{
Console.WriteLine(password);
if (password != confirmPassword) return this.BadRequest();
bool userExists = await this.Database.Users.FirstOrDefaultAsync(u => u.Username.ToLower() == username.ToLower()) != null;
if (userExists) return this.BadRequest();
this.Database.CreateUser(username, HashHelper.BCryptHash(password));
await this.Database.CreateUser(username, HashHelper.BCryptHash(password));
}
return this.Page();