< Summary - MechanicsSoftware — Coverage Report

Information
Class: MechanicsSoftware.Infrastructure.Security.BCryptPasswordHasher
Assembly: MechanicsSoftware.Infrastructure
File(s): /home/runner/work/mechanics-software/mechanics-software/src/MechanicsSoftware.Infrastructure/Security/BCryptPasswordHasher.cs
Line coverage
100%
Covered lines: 21
Uncovered lines: 0
Coverable lines: 21
Total lines: 31
Line coverage: 100%
Branch coverage
62%
Covered branches: 5
Total branches: 8
Branch coverage: 62.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()50%44100%
.ctor()75%44100%
Hash(...)100%11100%
Verify(...)100%11100%
Hash(...)100%11100%
Verify(...)100%11100%

File(s)

/home/runner/work/mechanics-software/mechanics-software/src/MechanicsSoftware.Infrastructure/Security/BCryptPasswordHasher.cs

#LineLine coverage
 1using MechanicsSoftware.Application.Abstractions;
 2
 3namespace MechanicsSoftware.Infrastructure.Security;
 4
 5public sealed class BCryptPasswordHasher : IPasswordHasher
 6{
 17    private readonly int _saltRounds;
 18
 159    public BCryptPasswordHasher()
 1510    {
 1411        _saltRounds = int.TryParse(
 1412            Environment.GetEnvironmentVariable("BCRYPT_SALT_ROUNDS"), out var rounds) && rounds > 0
 1913            ? rounds
 1414            : 12;
 1415    }
 316
 17    public string Hash(string password) =>
 1518        BCrypt.Net.BCrypt.HashPassword(password, _saltRounds);
 319
 20    public bool Verify(string password, string hash)
 921    {
 122        try
 923        {
 824            return BCrypt.Net.BCrypt.Verify(password, hash);
 325        }
 226        catch (BCrypt.Net.SaltParseException)
 227        {
 228            return false;
 29        }
 830    }
 31}