开发者网络 动网主机 支持论坛 邮局 帮助
当前位置:网络学院.Net专区Asp.Net开发 → .NET中带有口令加密的注册页面
.NET中带有口令加密的注册页面
日期:2002年1月4日 作者:icefox 人气:     [ ]
在ASP.NET中提供了加密的功能。名字空间System.Web.Security中包含了类FormsAuthentication,其中有一个方法HashPasswordForStoringInConfigFile。这个方法可以将用户提供的字符变成乱码,然后存储起来。注意此方法是不能继承的。
下面的代码就是在做注册页面时将数据加密后存储到数据库的过程
Imports System.Web.Security
Imports System.Data
Imports System.Data.SqlClient '////////所需要的名称空间

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim PassFormate As String
'///////////////EncryptPassword调用函数
PassFormate = EncryptPassword(uid.Text, "md5") '//////////或者是EncryptPassword(uid.Text, "sha1")
'TextBox2.Text = EncryptPassword(uid.Text, "md5")
'TextBox3.Text = EncryptPassword(uid.Text, "sha1")
'///////////这些大家自己试验吧
'TextBox4.Text = FormsAuthentication.FormsCookieName
'TextBox5.Text = FormsAuthentication.FormsCookiePath
'TextBox6.Text = FormsAuthentication.GetRedirectUrl(uid.Text, True)
'FormsAuthentication.SetAuthCookie(uid.Text, True)

Dim sql As String = "insert into pwd(uid,pwd) values(@uid,@pwd)"
Dim comm As SqlCommand = New SqlCommand(sql, conn)
conn.Open()
comm.Parameters.Add(New SqlParameter("@uid", SqlDbType.Char, 16))
comm.Parameters("@uid").Value = uid.Text
comm.Parameters.Add(New SqlParameter("@pwd", SqlDbType.Char, 16))
comm.Parameters("@pwd").Value = PassFormate
comm.ExecuteNonQuery()

End Sub

'////////////////定义加密函数,可以随时调用。
Function EncryptPassword(ByVal password As String, ByVal passwordformate As String)
If passwordformate = "sha1" Then
EncryptPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "sha1")
ElseIf passwordformate = "md5" Then
EncryptPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "md5")
Else
EncryptPassword = ""
End If

End Function
至于用户的验证也是一样的思路了。

(出处:开发者俱乐部)

相关文章:
 
·加密處理使密碼更安全[转]
·一段在asp中加密与解密对应的函数
·加密處理使密碼更安全[CFS編碼加密]
·RC4经典加密算法VB版本代码
·在asp中通过vbs类实现rsa加密与解密
·给大家一个新的加密方法,C#的
·一段加密函数(base64)
·一段加密函数
·MD5加密的javascript实现例子
·MD5不可逆加密算法的ASP实现实例
相关软件:
 
·81238工作室QQ信息群发广播器 v2.10.28 未加密版
说明:本站部分内容收集于网络,如有侵犯您的权益请来信告知,我们会第一时间进行处理,谢谢
 → 特别推荐
 → 热点TOP10

关于本站 | 诚聘英才 | 业务合作 | 联系我们 | 广告合作 | 收藏本站

海口动网先锋网络科技有限公司版权所有
Copyright ? 2000 - 2003 AspSky.Net
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077