扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:廖煜嵘编译 来源:天极网 2007年11月7日
关键字: Windows
Imports Microsoft.VisualBasic Imports System.Data Public Class AccessMembershipProvider Inherits MembershipProvider End Class |
<system.web> <authentication mode="Forms"/> <membership defaultProvider="AccessMembershipProvider" > <providers> <add name="AccessMembershipProvider" type="AccessMembershipProvider" requiresQuestionAndAnswer="true" connectionString="Provider=Microsoft.Jet. OLEDB.4.0;Data Source=C:\NewMembershipProvider\ App_Data\Members.mdb;Persist Security Info=False" /> </providers> </membership> </system.web> |
Private connStr As String Private comm As New OleDb.OleDbCommand Private _requiresQuestionAndAnswer As Boolean Private _minRequiredPasswordLength As Integer |
Public Overrides Sub Initialize(ByVal name As String, ByVal config As System.Collections.Specialized.NameValueCollection) ’===retrives the attribute values set in ’web.config and assign to local variables=== If config("requiresQuestionAndAnswer") = "true" Then _ _requiresQuestionAndAnswer = True connStr = config("connectionString") MyBase.Initialize(name, config) End Sub |
Public Overrides ReadOnly Property _ RequiresQuestionAndAnswer() _ As Boolean Get If _requiresQuestionAndAnswer = True Then Return True Else Return False End If End Get End Property |
Public Overrides Function CreateUser(ByVal username As String, ByVal password As String, ByVal email As String, ByVal passwordQuestion As String, ByVal passwordAnswer As String, ByVal isApproved As Boolean, ByVal providerUserKey As Object, ByRef status As System.Web.Security.MembershipCreateStatus) As System.Web.Security.MembershipUser Dim conn As New OleDb.OleDbConnection(connStr) Try conn.Open() Dim sql As String = "INSERT INTO Membership VALUES (" & _ "@username, @password, @email, " & _ " @passwordQuestion, @passwordAnswer )" Dim comm As New OleDb.OleDbCommand(sql, conn) comm.Parameters.AddWithValue("@username", username) comm.Parameters.AddWithValue("@password", password) comm.Parameters.AddWithValue("@email", email) comm.Parameters.AddWithValue("@passwordQuestion", passwordQuestion) comm.Parameters.AddWithValue("@passwordAnswer", passwordAnswer) Dim result As Integer = comm.ExecuteNonQuery() conn.Close() status = MembershipCreateStatus.Success Dim user As New MembershipUser("AccessMembershipProvider", username, Nothing, email, passwordQuestion, Nothing, True, False, Now, Nothing, Nothing, Nothing, Nothing) Return user Catch ex As Exception status = MembershipCreateStatus.UserRejected Return Nothing End Try End Function |
Dim user As New MembershipUser("AccessMembershipProvider", username, Nothing, email, passwordQuestion, Nothing, True, False, Now, Nothing, Nothing, Nothing, Nothing) |
Public Overrides Function ValidateUser( _ ByVal username As String, _ ByVal password As String) As Boolean Dim conn As New OleDb.OleDbConnection(connStr) Try conn.Open() Dim sql As String = _ "Select * From Membership WHERE " & _ "username=@username AND password=@password" Dim comm As New OleDb.OleDbCommand(sql, conn) comm.Parameters.AddWithValue("@username", _ username) comm.Parameters.AddWithValue("@password", _ password) Dim reader As OleDb.OleDbDataReader = _ comm.ExecuteReader If reader.HasRows Then Return True Else Return False End If conn.Close() Catch ex As Exception Console.Write(ex.ToString) Return False End Try End Function |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者