zoukankan      html  css  js  c++  java
  • NopCommerce 定制系列(一):增加 Sha256+Base64 加密

    一、Nop.Core.Domain.Customers.PasswordFormat ( enum  ),增加一个 “S256_B64”。

    二、Libraries\Nop.Services\Security\EncryptionService.cs 及其接口增加对应方法

       1: #region
       2: /// <param name="str">string str:被加密的字符串</param>
       3: /// <returns>返回加密后的字符串</returns>
       4: public virtual string S256_B64Encrypt(string str)
       5: {
       6:     System.Security.Cryptography.SHA256 s256 = new System.Security.Cryptography.SHA256Managed();
       7:  
       8:     byte[] byte1;
       9:     byte1 = s256.ComputeHash(Encoding.Default.GetBytes(str));
      10:     s256.Clear();
      11:  
      12:     return Convert.ToBase64String(byte1);
      13: }
      14: #endregion

    三、增加对 “S256_B64”的支持,code中有若干处。

       1: switch (customer.PasswordFormat)
       2:                 {
       3:                     case PasswordFormat.Encrypted:
       4:                         oldPwd = _encryptionService.EncryptText(request.OldPassword);
       5:                         break;
       6:                     case PasswordFormat.Hashed:
       7:                         oldPwd = _encryptionService.CreatePasswordHash(request.OldPassword, customer.PasswordSalt, _customerSettings.HashedPasswordFormat);
       8:                         break;
       9:                     #region     这里增加对  “S256_B64”的支持,code中有若干处。
      10:                     case PasswordFormat.S256_B64:
      11:                         oldPwd = _encryptionService.S256_B64Encrypt(request.OldPassword);
      12:                         break;
      13:                     #endregion
      14:                     default:
      15:                         oldPwd = request.OldPassword;
      16:                         break;
      17:                 }

    四、广谱搜索关键字“PasswordFormat.Hashed”,将其改成想用的加密方法即可。

  • 相关阅读:
    等级,
    JS高阶---回调函数
    JS高阶---函数
    JS高阶---对象
    JS高阶---数据、变量、内存
    JS高阶---简介+数据类型
    JS里==和===区别
    vue中assets和static的区别
    vue2.0 实现导航守卫(路由守卫)---登录验证
    exports与module.exports,export与export default 之间的关系和区别
  • 原文地址:https://www.cnblogs.com/luckjason/p/2454143.html
Copyright © 2011-2022 走看看