PasswordRequirement 0.0.1-alpha.4

This is a prerelease version of PasswordRequirement.
dotnet add package PasswordRequirement --version 0.0.1-alpha.4                
NuGet\Install-Package PasswordRequirement -Version 0.0.1-alpha.4                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PasswordRequirement" Version="0.0.1-alpha.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PasswordRequirement --version 0.0.1-alpha.4                
#r "nuget: PasswordRequirement, 0.0.1-alpha.4"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PasswordRequirement as a Cake Addin
#addin nuget:?package=PasswordRequirement&version=0.0.1-alpha.4&prerelease

// Install PasswordRequirement as a Cake Tool
#tool nuget:?package=PasswordRequirement&version=0.0.1-alpha.4&prerelease                

PasswordRequirement

Sample Usage

Create Verifier Service

You can Create Class To Implement Verifier Service

public class MyPasswordVerifierService : IPasswordVerifierService
{
    /// <summary>
    /// Verifier Password By Combination Rules, if not valid will return list error
    /// </summary>
    /// <param name="password"></param>
    /// <returns></returns>
    public async Task<List<string>> VerifyAsync(UserData userData, CancellationToken cancellationToken = default)
    {
        var verifiers = new List<PasswordVerifier>();
        verifiers.Add(new VerifiedContainsLetterAndNumber());
        verifiers.Add(new VerifiedContainsLowerAndUpperCase());
        // Add Other Verifiers here
        
        var errorList = new List<string>();
        foreach (var verifier in verifiers)
        {
            var result = verifier.Verified(userData);
            if (string.IsNullOrEmpty(result)) continue;
            errorList.Add(result);
        }

        return errorList;
    }
}

Inject On Startup (.NETCore)

services.AddPasswordRequirement<MyPasswordVerifierService>();

Get Service (.NETCore)

public class MyService {
    private readonly IPasswordVerifierService _passwordVerifier;
    public MyService(IPasswordVerifierService passwordVerifier) {
        _passwordVerifier = passwordVerifier;
    }
    
    private readonly List<string> _errors = new List<string>();
    private void AddError(string error) 
    {
        _errors.Add(error);
    }
    public IReadOnlyList<string> Errors => _errors.AsReadOnly();
    
    public async Task<bool> ValidatePassword(UserData userData, CancellationToken cancellationToken = default) 
    {
        var errorResult = await _passwordVerifier.VerifyAsync(userData, cancellationToken);
        foreach (var error in errorResult)
        {
            AddError(error);
        }
        return Errors.Count == 0;
    }
}

Using on NETFramework

public class MyService {
    private readonly IPasswordVerifierService _passwordVerifier;
    public MyService(IPasswordVerifierService passwordVerifier) {
        _passwordVerifier = passwordVerifier;
    }
    
    private readonly List<string> _errors = new List<string>();
    private void AddError(string error) 
    {
        _errors.Add(error);
    }
    public IReadOnlyList<string> Errors => _errors.AsReadOnly();
    
    public async Task<bool> ValidatePassword(UserData userData, CancellationToken cancellationToken = default) 
    {
        var errorResult = await _passwordVerifier.VerifyAsync(userData, cancellationToken);
        foreach (var error in errorResult)
        {
            AddError(error);
        }
        return Errors.Count == 0;
    }
}
public class Program {
    public void Main() 
    {
        var service = new MyService();
        var isValid = service.ValidatePassword(new UserData("Test")).Result;
        ...
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
.NET Framework net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.1-alpha.4 89 7/14/2024
0.0.1-alpha.3 47 7/14/2024
0.0.1-alpha.2 50 7/14/2024
0.0.1-alpha.1 48 7/14/2024