From 9cd0abf97f48c21ae0cf08b78da0203ebebefef7 Mon Sep 17 00:00:00 2001 From: Kirill Poletaev Date: Fri, 22 Mar 2024 16:52:52 +0300 Subject: [PATCH] Use username hash as userhandle --- .../Services/Implementation/DefaultUserService.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/demo/WebAuthn.Net.Demo.Mvc/Services/Implementation/DefaultUserService.cs b/demo/WebAuthn.Net.Demo.Mvc/Services/Implementation/DefaultUserService.cs index 8235ae0..edfea67 100644 --- a/demo/WebAuthn.Net.Demo.Mvc/Services/Implementation/DefaultUserService.cs +++ b/demo/WebAuthn.Net.Demo.Mvc/Services/Implementation/DefaultUserService.cs @@ -1,4 +1,6 @@ -using System.Text.Json; +using System.Security.Cryptography; +using System.Text; +using System.Text.Json; using System.Text.Json.Serialization; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.WebUtilities; @@ -106,7 +108,7 @@ private void Write(HttpContext httpContext, TypedInternalApplicationUser[] items private static TypedInternalApplicationUser Create(string userName) { - var userHandle = Guid.NewGuid().ToByteArray(); + var userHandle = SHA256.HashData(Encoding.UTF8.GetBytes(userName)); var createdAt = DateTimeOffset.FromUnixTimeSeconds(DateTimeOffset.UtcNow.ToUnixTimeSeconds()); return new(userHandle, userName, createdAt); }