本文介绍了是否要替换FormsAuthentication.HashPasswordForStoringInConfigFile?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级到.Net 4.5之后,我现在收到警告"System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile已过时",建议使用成员资格API.

After upgrading to .Net 4.5, I am now getting the warning that "System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile is obsolete" and the suggestion is to use the membership APIs instead.

这对新项目来说非常好,但是在现阶段(存在用户数据和哈希密码),我不能很好地更改为具有可能不同的哈希方法的自定义成员资格提供程序.

This is all very well and good for new projects, but at this stage (with user data and hashed passwords existing), I can't very well change to a custom membership provider with potentially different ways of hashing.

对于此类问题,推荐的前进方法是什么?继续使用过时"调用显然不是建议的路径,是否已将其替换为仅使用成员资格API"以外的其他东西?

Whats the recommended way forward for issues like this? Continuing to use "obsolete" calls is obviously not the suggested path, so has it been replaced by something else other than "just use the membership APIs"?

推荐答案

这是SHA1变体的解决方案.

This is a solution for SHA1 variant.

     public static string GetSwcSHA1(string value)
     {
        SHA1 algorithm = SHA1.Create();
        byte[] data = algorithm.ComputeHash(Encoding.UTF8.GetBytes(value));
        string sh1 = "";
        for (int i = 0; i < data.Length; i++)
        {
            sh1 += data[i].ToString("x2").ToUpperInvariant();
        }
        return sh1;
     }

对于MD5,您只需将算法更改为:

For MD5 you only need to change the algorithm to:

MD5 algorithm = MD5.Create();


希望您不介意,只需在上面添加代码的VB.NET变体即可:


Hope you don't mind, just going to add a VB.NET variant of your code above:

    Public Shared Function CreateHash(saltAndPassword) As String
        Dim Algorithm As SHA1 = SHA1.Create()
        Dim Data As Byte() = Algorithm.ComputeHash(Encoding.UTF8.GetBytes(saltAndPassword))
        Dim Hashed As String = ""

        For i As Integer = 0 To Data.Length - 1
            Hashed &= Data(i).ToString("x2").ToUpperInvariant()
        Next

        Return Hashed
    End Function

这篇关于是否要替换FormsAuthentication.HashPasswordForStoringInConfigFile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 12:57