You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
haoliang-net/tools/GenHash/Program.cs

39 lines
1.2 KiB
C#

using System;
using BCrypt.Net;
/// <summary>
/// 临时工具:验证并生成 BCrypt 密码哈希
/// </summary>
class Program
{
static void Main()
{
var password = "admin123";
var existingHash = "$2a$10$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy";
Console.WriteLine("=== BCrypt 验证测试 ===");
Console.WriteLine($"密码: {password}");
Console.WriteLine($"现有Hash: {existingHash}");
Console.WriteLine($"Hash长度: {existingHash.Length}");
try
{
var result = BCrypt.Net.BCrypt.Verify(password, existingHash);
Console.WriteLine($"验证结果: {result}");
}
catch (Exception ex)
{
Console.WriteLine($"验证异常: {ex.GetType().Name} - {ex.Message}");
}
// 生成新 hash
var newHash = BCrypt.Net.BCrypt.HashPassword(password, 10);
Console.WriteLine($"\n新生成的Hash: {newHash}");
Console.WriteLine($"新Hash长度: {newHash.Length}");
// 验证新 hash
var verifyNew = BCrypt.Net.BCrypt.Verify(password, newHash);
Console.WriteLine($"新Hash验证: {verifyNew}");
}
}