Skip to content

Latest commit

 

History

History
91 lines (59 loc) · 2.37 KB

File metadata and controls

91 lines (59 loc) · 2.37 KB

Hasher.KenKoV1

Minimal .NET library for secure password hashing using PBKDF2 (HMACSHA512) with support for salt, optional pepper, and configurable iterations.


Why this project?

This library was created to demonstrate secure authentication fundamentals in .NET and to provide a small, dependency-free hashing component that can be integrated into any application (e.g., Web APIs, MVC apps, background services).


Features

  • PBKDF2 (HMACSHA512) password hashing
  • Secure random salt generation
  • Optional pepper support (stored outside the database)
  • Configurable iteration count
  • Simple password verification
  • Easy integration into any .NET application

Installation

.NET CLI

dotnet add package Hasher.KenKoV1 --version 1.0.0

NuGet Package Manager

Install-Package Hasher.KenKoV1 -Version 1.0.0

Quick Start

using Hasher.Services;

var hashService = new HashService();

string password  = "MySecurePassword123!";
string salt      = hashService.GenerateSalt(16);
string pepper    = "<your-secret-pepper>";
int iterations   = 100_000;

string hash = hashService.GeneratePasswordHash(password, salt, pepper, iterations);

// Later for verification:
bool isValid = hashService.VerifyPassword(password, salt, pepper, iterations, hash);

Security Recommendations

  • Salt should be unique per user and stored in the database.
  • Pepper should be stored outside the database (e.g., environment variable or secret vault).
  • Iteration count should match your security and performance requirements (start around 100,000+ depending on environment).
  • Never reuse the same salt across different users.
  • Always use HTTPS when transmitting passwords.

Design Principles

  • Minimal and dependency-free
  • Explicit parameter control (salt, pepper, iterations)
  • Clear separation between hashing and verification
  • Security-first implementation approach

API Overview

Method Description
GenerateSalt(int length) Generates a secure random salt (Base64).
GeneratePasswordHash(string password, string salt, string pepper, int iterations) Generates a PBKDF2 hash and returns it as Base64.
VerifyPassword(string password, string salt, string pepper, int iterations, string hashToCompare) Recomputes the hash and compares it.

License

MIT