网站链接: 环球农商网
当前位置: 首页 > 资讯动态  > 平台资讯

.NET中带有口令加密的注册页面

2019/3/5 11:48:38 人评论

在ASP.NET中提供了加密的功能。名字空间System.Web.Security中包含了类FormsAuthentication,其中有一个方法HashPasswordForStoringInConfigFile。这个方法可以将用户提供的字符变成乱码,然后存储起来。注意此方法是不能继承的。下面的代码就是在做注册页面时将数据加密…

在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
至于用户的验证也是一样的思路了。

相关资讯

  • document.cookie:客户端操作cookie

    我们已经知道,在 document 对象中有一个 cookie 属性。但是 Cookie 又是什么?“某些 Web 站点在您的硬盘上用很小的文本文件存储了一些信息,这些文件就称为 Cookie。”—— MSIE 帮助。一般来说,Cookies 是 CGI 或类似,比 HTML …

    2019/4/12 8:18:11
  • 用ASP实现分级权限控制

    本文实现的是一个帐务管理系统中分级权限的控制,程序使用ASP和JavaScript编写,在装有IIS4.0的win NT服务器上运行,速度快,易维护。  权限级别划分如下:  ①、院长和财务科长:不能输入,可以无限制查询、统计;  ②、副院长:不能输入,可以查询、统计其分管部…

    2019/4/12 8:18:11
  • ASP实现Rewrite模拟生成静态页效

    以前刚刚懂404.asp的时候,曾经幻想把所有程序代码写到404.asp中,实现一个模拟生成静态网页的站,如果程序小还可以,用404.asp实现Rewrite还是一个不错的选择,如果程序代码多达100000行,恐怕就要开始爬了  直到看到asp的Server.Transfer,用404模拟生成静态页的站的念…

    2019/4/12 8:18:11
  • ASP随机涵数生成100条8位字母和数字混合密码

    <%for i = 1 to 100%><%Randomizepass=""Do While Len(pass)<8 随机密码位数num1=CStr(Chr((57-48)*rnd+48)) 0~9num2=CStr(Chr((122-97)*rnd+97)) a~zpass=pass&num1&num2loop原创:www.devdao.com%><%=pass%><br><%next…

    2019/4/12 8:18:11

共有条评论 网友评论

验证码: 看不清楚?