Use of the MD5 password database: Meng will come from: [it] would be a wonderful world Meng Date: 2003 at 4:57:50 on April 26
.NET provides data encryption classes, which use examples to explain how to use MD5 for data encryption. First, create a useeraccount table, the fields: username and password, type is varchar (25) and binary (16), the following ASP.NET code is the specific implementation of creating a user: <% @ Import namespace = "system .Security.cryptography "%>
<% @ Import namespace = "system.text"%>
<% @ Import namespace = "system.data"%>
<% @ Import namespace = "system.data.sqlclient"%>
Sub CreateAccount (Sender As Object, E AS Eventargs)
'1. Create a connection
Const strconnstring as string
StrConnstring = "Data Source = .; initial catalog = test; user ID = sa; password =;"
DIM Objconn as new SqlConnection (StrConnString)
'2. Create a Command object
DIM strsql as string = _
"INSERT INTO USERACCOUNT (UserName, Password) & _
"@Username, @password"
DIM Objcmd As New Sqlcommand (strsql, objconn)
'3. Creating parameters
Dim paramusername as sqlparameter
ParamuserName = New Sqlparameter ("@ username", SqldbType.varchar, 25)
ParamuserName.Value = txtusername.text
Objcmd.parameters.add (paramusername)
'Encrypting password field
DIM MD5HASHER AS New MD5CryptoServiceProvider ()
DIM Hashedbytes as Byte ()
DIM ENCODER AS New UTF8ENCODING ()
Hashedbytes = md5hasher.computehash (eNCoder.getBytes (txtpwd.text))
Dim parampwd as sqlparameter
Parampwd = New SqlParameter ("@ password", sqldbtype.binary, 16)
Parampwd.value = Hashedbytes
Objcmd.Parameters.Add (parampwd)
'Insert the database
Objconn.open ()
Objcmd.executenonQuery ()
Objconn.close ()
'Redirect Other Page
End Sub script>