Saturday, March 24, 2012

md5 hash and code behind

Hi,

I'am trying to print a md5 hash on the html page by using a codebehind file, this is my code:

-------
HTML
-------
<%@dotnet.itags.org. Page Language="VB" src="http://pics.10026.com/?src=CodeBehind.vb" Inherits="CodeBehind" %>
<html>
<head>
</head>
<body>
<asp:Label id="lbMessage" runat="server"></asp:Label>
<form runat="server">
<asp:TextBox id="txtStringToHash" runat="server"></asp:TextBox>
<asp:Button id="btnHash" runat="server" Text="Hash" onclick="btnHash_Click"></asp:Button>
</form>
</body>
</html
-------
codebehind
-------
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Public Class CodeBehind : Inherits Page
Public lbMessage As Label
Public btnHash As Button
Public txtStringToHash As TextBox

Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub

Public Sub btnHash_Click(ByVal sender As Object, ByVal e As EventArgs)
lbMessage.Text = FormsAuthentication.HashPasswordForStoringInConfigFile(txtStringToHash.Text, "MD5")
End Sub
End Class

------------------

The bug is on this line:
lbMessage.Text = FormsAuthentication.HashPasswordForStoringInConfigFile(txtStringToHash.Text, "MD5")

It says FormsAuthentication isnt declared, anyone know how to fix this?did you import the appropriate namespace for formsauthentication?

Import System.Security.Cryptography

http://aspnet.4guysfromrolla.com/articles/103002-1.aspx
Yea it works now :D

Thanks!

No comments:

Post a Comment