Path: redb/redb.Templates/templates/redb-bff/RedbBff.Web/Services/WebUsers.cs
Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Templates/templates/redb-bff/RedbBff.Web/Services/WebUsers.cs
----
using System.Security.Cryptography;
using System.Text;
namespace RedbBff.Web.Services;
///
/// The users who can sign in, from Web:Users in configuration. A stand-in that keeps the template
/// small: a real application keeps its users in a store of its own, for example redb.Identity.
///
public sealed class WebUsers(IConfiguration configuration)
{
/// The user's role when the login and password match, otherwise null.
public string? Check(string login, string password)
{
var user = configuration.GetSection($"Web:Users:{login}");
var expected = user["Password"];
if (string.IsNullOrEmpty(login) || expected is null)
return null;
// Constant-time comparison, so the answer time does not tell how much of the password was right.
return CryptographicOperations.FixedTimeEquals(Encoding.UTF8.GetBytes(expected), Encoding.UTF8.GetBytes(password))
? user["Role"] ?? throw new InvalidOperationException($"Web:Users:{login}:Role is not set.")
: null;
}
}