From 3684863bbfa0ef7926e1bc02d4ea3330e6b2c8bd Mon Sep 17 00:00:00 2001 From: Andreas Guldborg Hansen Date: Tue, 5 Mar 2024 19:00:06 +0100 Subject: [PATCH] Adds encoding to password to match the Analog app (#29) --- Shifty.App/Services/AuthenticationService.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Shifty.App/Services/AuthenticationService.cs b/Shifty.App/Services/AuthenticationService.cs index e8d7bad..fa4f1aa 100644 --- a/Shifty.App/Services/AuthenticationService.cs +++ b/Shifty.App/Services/AuthenticationService.cs @@ -1,4 +1,7 @@ using System.Threading.Tasks; +using System; +using System.Security.Cryptography; +using System.Text; using Blazored.LocalStorage; using LanguageExt.UnsafeValueAccess; using Shifty.App.Authentication; @@ -19,9 +22,20 @@ public AuthenticationService(IAccountRepository accountRepository, CustomAuthSta _localStorage = storageService; } + private static string EncodePasscode(string passcode) + { + byte[] bytes = Encoding.UTF8.GetBytes(passcode); + using (SHA256 sha256 = SHA256.Create()) + { + byte[] passcodeHash = sha256.ComputeHash(bytes); + return Convert.ToBase64String(passcodeHash); + } + } + public async Task LoginUser(string username, string password) { - var either = await _accountRepository.LoginAsync(username, password); + var encodedPassword = EncodePasscode(password); + var either = await _accountRepository.LoginAsync(username, encodedPassword); if (either.IsLeft) {