如何在frm(winForms)中创建PasswordHash asp身份o生成PasswordHash

时间:2015-09-03 22:48:31

标签: asp.net vb.net winforms asp.net-identity identity

美好的一天,你可以帮我说明生成autmaticamente身份模板的PasswordHash类型,如果字段和BD等于发送的参数(通过),我需要创建一个响应tru的web服务

当我调用创建asp.net的模板时,它是:

Protected Sub LogIn(sender As Object, e As EventArgs)
        If IsValid Then
            ' Validate the user password
            Dim manager = Context.GetOwinContext().GetUserManager(Of ApplicationUserManager)()
            Dim signinManager = Context.GetOwinContext().GetUserManager(Of ApplicationSignInManager)()

            ' This doen't count login failures towards account lockout
            ' To enable password failures to trigger lockout, change to shouldLockout := True
            Dim result = signinManager.PasswordSignIn(Email.Text, Password.Text, RememberMe.Checked, shouldLockout:=True)

            Select Case result
                Case SignInStatus.Success
                    IdentityHelper.RedirectToReturnUrl(Request.QueryString("ReturnUrl"), Response)
                    Exit Select
                Case SignInStatus.LockedOut
                    Response.Redirect("/Account/Lockout")
                    Exit Select
                Case SignInStatus.RequiresVerification
                    Response.Redirect(String.Format("/Account/TwoFactorAuthenticationSignIn?ReturnUrl={0}&RememberMe={1}",
                                                    Request.QueryString("ReturnUrl"),
                                                    RememberMe.Checked),
                                      True)
                    Exit Select
                Case Else
                    FailureText.Text = "Intento inválido de inicio de sesión"
                    ErrorMessage.Visible = True
                    Exit Select
            End Select
        End If
    End Sub

我需要创建加密密码以将其与BD

进行比较

2 个答案:

答案 0 :(得分:1)

class正在Identity框架中进行密码散列。

答案 1 :(得分:1)

使用用户管理器的PasswordHasher属性生成散列密码并将其与存储的数据进行比较:

 var userManager=HttpContext.GetOwinContext().GetUserManager<ApplicationUSerManager>();
 string hashedPassword=userManager.PasswordHasher.HashPassword("myPass");