How? Encrypt and Decrypt user membership passwords in ASP.NET

后端 未结 4 605
名媛妹妹
名媛妹妹 2021-01-05 05:17

We are creating a new site using ASP.NET membership provider for user registration and log in. Our old system encrypted user passwords so that we could recover them if we ne

4条回答
  •  春和景丽
    2021-01-05 06:09

    Imports System.Web.Security
    
    Public Class PasswordRecovery
        Inherits SqlMembershipProvider
    
        Public Function GetDecryptedPassword(ByVal password As String) As String
            Try
                Dim _encodedPassword() As Byte = Convert.FromBase64String(password)
                Dim _bytes() As Byte = DecryptPassword(_encodedPassword)
                If _bytes Is Nothing Then
                    Return ""
                Else
                    Return System.Text.Encoding.Unicode.GetString(_bytes, &H10, _bytes.Length - &H10)
                End If
            Catch ex As Exception
                Throw New Exception("Error decrypting password.", ex)
            End Try
        End Function
    End Class
    

提交回复
热议问题