Exemple #1
0
    /// <summary>
    /// Gets whether the specified password is found in a password list
    /// </summary>
    /// <param name="password">
    /// The password to check
    /// </param>
    /// <param name="cancellationToken">
    /// The <see cref="CancellationToken"/> for this operation
    /// </param>
    /// <returns>
    /// An awaitable <see cref="Task{TResult}"/> with a <see cref="bool"/>
    /// indicating whether the password was found or not
    /// </returns>
    private async Task <bool> IsPwnedPasswordInternalAsync(string password, CancellationToken cancellationToken)
    {
        Throw.ArgumentNull.WhenNullOrWhiteSpace(password, nameof(password));
        this.ThrowIfDisposed();

        var result = false;

        var(kAnonimityPart, kAnonimityRemainder) = KAnonimityHelper.GetKAnonimityPartsForPassword(password);

        var requestUri = UriFactory.GetPwnedPasswordUri(kAnonimityPart);

        using var requestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri);

        if (this._clientSettings.RequestPaddingForPwnedPasswordResponses)
        {
            requestMessage.Headers.Add("Add-Padding", "true");
        }

        using var response = await this.ExecuteRequestAsync(requestMessage, cancellationToken).ConfigureAwait(false);

        if (response.StatusCode == HttpStatusCode.OK)
        {
            var content = await response.Content
                          .ReadAsStringAsync()
                          .ConfigureAwait(false);

            result = content.Contains(kAnonimityRemainder);
        }

        return(result);
    }
Exemple #2
0
    public void GetKAnonimityPartsForPassword_WithPassword_GeneratesValidKAnonimityParts(string password, string expectedKAnonimityPart, string expectedKAnonimityRemainder)
    {
        var(kAnonimityPart, kAnonimityRemainder) = KAnonimityHelper.GetKAnonimityPartsForPassword(password);

        Assert.NotNull(kAnonimityPart);
        Assert.Equal(5, kAnonimityPart.Length);
        Assert.Equal(expectedKAnonimityPart, kAnonimityPart);

        Assert.NotNull(kAnonimityRemainder);
        Assert.Equal(35, kAnonimityRemainder.Length);
        Assert.Equal(expectedKAnonimityRemainder, kAnonimityRemainder);
    }
    public (string, string) GetKAnonimityPartsForPassword(string password)
    {
        var result = KAnonimityHelper.GetKAnonimityPartsForPassword(password);

        return(result);
    }
Exemple #4
0
 public void GetKAnonimityPartsForPassword_WithNullPassword_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => KAnonimityHelper.GetKAnonimityPartsForPassword(null));
 }