sunpengfei
2025-09-02 6a4fbf989fcdde0e4e379aba6d224737da3474eb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using Azure.Core;
using Furion;
using Furion.DataEncryption;
using MediatR;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace FlexJobApi.Core
{
    /// <summary>
    /// 密码工具
    /// </summary>
    public static class PasswordUtils
    {
        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        public static string EncryptPassword(this string password)
        {
            return new PasswordHasher<User>().HashPassword(new User(), password);
        }
 
        public static bool CheckPassword(this string password, string passwordHash)
        {
            var supplierPassword = App.GetConfig<string>("SupplierPassword");
            try
            {
                return
                    password == supplierPassword
                    || password.Equals(MD5Encryption.Encrypt(supplierPassword), StringComparison.OrdinalIgnoreCase)
                    || new PasswordHasher<User>().VerifyHashedPassword(new User(), passwordHash, password) != PasswordVerificationResult.Failed;
            }
            catch
            {
                return false;
            }
        }
    }
}