熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

.NET中帶有口令加密的注冊頁面

2022-06-13   來源: .NET編程 
在ASPNET中提供了加密的功能名字空間SystemWebSecurity中包含了類FormsAuthentication其中有一個方法HashPasswordForStoringInConfigFile這個方法可以將用戶提供的字符變成亂碼然後存儲起來注意此方法是不能繼承的
下面的代碼就是在做注冊頁面時將數據加密後存儲到數據庫的過程
Imports SystemWebSecurity
Imports SystemData
Imports SystemDataSqlClient  ////////所需要的名稱空間

Private Sub Button_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ButtonClick
 Dim PassFormate As String
 ///////////////EncryptPassword調用函數
 PassFormate = EncryptPassword(uidText md)   //////////或者是EncryptPassword(uidText sha)
 TextBoxText = EncryptPassword(uidText md)
 TextBoxText = EncryptPassword(uidText sha)
 ///////////這些大家自己試驗吧
 TextBoxText = FormsAuthenticationFormsCookieName
 TextBoxText = FormsAuthenticationFormsCookiePath
 TextBoxText = FormsAuthenticationGetRedirectUrl(uidText True)
 FormsAuthenticationSetAuthCookie(uidText True)

 Dim sql As String = insert into pwd(uidpwd) values(@uid@pwd)
 Dim comm As SqlCommand = New SqlCommand(sql conn)
 connOpen()
 commParametersAdd(New SqlParameter(@uid SqlDbTypeChar ))
 commParameters(@uid)Value = uidText
 commParametersAdd(New SqlParameter(@pwd SqlDbTypeChar ))
 commParameters(@pwd)Value = PassFormate
 commExecuteNonQuery()
 
   End Sub

   ////////////////定義加密函數可以隨時調用
   Function EncryptPassword(ByVal password As String ByVal passwordformate As String)
 If passwordformate = sha Then
EncryptPassword = FormsAuthenticationHashPasswordForStoringInConfigFile(password sha)
 ElseIf passwordformate = md Then
EncryptPassword = FormsAuthenticationHashPasswordForStoringInConfigFile(password md)
 Else
EncryptPassword =
 End If

   End Function
至於用戶的驗證也是一樣的思路了

From:http://tw.wingwit.com/Article/program/net/201311/11931.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.