< Summary

Information
Class: Elsa.Identity.Services.DefaultUserCredentialsValidator
Assembly: Elsa.Identity
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Services/DefaultUserCredentialsValidator.cs
Line coverage
40%
Covered lines: 4
Uncovered lines: 6
Coverable lines: 10
Total lines: 36
Line coverage: 40%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ValidateAsync()0%2040%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Services/DefaultUserCredentialsValidator.cs

#LineLine coverage
 1using Elsa.Extensions;
 2using Elsa.Identity.Contracts;
 3using Elsa.Identity.Entities;
 4
 5namespace Elsa.Identity.Services;
 6
 7/// <summary>
 8/// Validates user credentials
 9/// </summary>
 10public class DefaultUserCredentialsValidator : IUserCredentialsValidator
 11{
 12    private readonly IUserProvider _userProvider;
 13    private readonly ISecretHasher _secretHasher;
 14
 15    /// <summary>
 16    /// Initializes a new instance of the <see cref="DefaultUserCredentialsValidator"/> class.
 17    /// </summary>
 118    public DefaultUserCredentialsValidator(IUserProvider userProvider, ISecretHasher secretHasher)
 19    {
 120        _userProvider = userProvider;
 121        _secretHasher = secretHasher;
 122    }
 23
 24    /// <inheritdoc />
 25    public async ValueTask<User?> ValidateAsync(string username, string password, CancellationToken cancellationToken = 
 26    {
 027        var user = await _userProvider.FindByNameAsync(username, cancellationToken);
 28
 029        if (user == null)
 030            return null;
 31
 032        var isValidPassword = _secretHasher.VerifySecret(password, user.HashedPassword, user.HashedPasswordSalt);
 33
 034        return isValidPassword ? user : null;
 035    }
 36}