
-
Loading...
-
ardilo
- Joined on 12-29-2007, 5:50 AM
- Posts 37
|
This is the code of the web.config file:
<membership defaultProvider="AccessMembershipProvider" > <providers> <add name="AccessMembershipProvider" type="AccessMembershipProvider" requiresQuestionAndAnswer="true" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|xxx.mdb;Jet OLEDB:Database Password=xxxxxxx;Persist Security Info=False" enablePasswordRetrieval="true" enablePasswordReset="false" applicationName="/" requiresUniqueEmail="true" minRequiredPasswordLength="1" minRequiredNonalphanumericCharacters="0" passwordFormat="Encrypted" maxInvalidPasswordAttempts="5" passwordAttemptWindow="10" passwordStrengthRegularExpression="" /> </providers> </membership> <authentication mode="Forms" />
And this is the App_Code:
Imports Microsoft.VisualBasic
Imports System.DataPublic Class AccessMembershipProvider
Inherits MembershipProvider
'---for database access use---
Private connStr As StringPrivate comm As New OleDb.OleDbCommand
Private _requiresQuestionAndAnswer As Boolean
Private _minRequiredPasswordLength As IntegerPublic 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 = TrueconnStr = config("connectionString")
MyBase.Initialize(name, config)
End Sub
Public Overrides Property ApplicationName() As String
Get
End GetSet(ByVal value As String)
End Set
End Property
Public Overrides Function ChangePassword(ByVal username As String, ByVal oldPassword As String, ByVal newPassword As String) As Boolean
Return Membership.Provider.ChangePassword(username, oldPassword, newPassword) = True
End Function
Public Overrides Function ChangePasswordQuestionAndAnswer(ByVal username As String, ByVal password As String, ByVal newPasswordQuestion As String, ByVal newPasswordAnswer As String) As Boolean
End FunctionPublic 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)
'----perform checking all the relevant checks here
' and set the status of the error accordingly, e.g.:
'status = MembershipCreateStatus.InvalidPassword
'status = MembershipCreateStatus.InvalidAnswer
'status = MembershipCreateStatus.InvalidEmail
'---add the user to the database
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 userCatch ex As Exception
'---failed; determine the reason why
status = MembershipCreateStatus.UserRejected
Return Nothing
End Try
End Function
Public Overrides Function DeleteUser(ByVal username As String, ByVal deleteAllRelatedData As Boolean) As Boolean
End Function
Public Overrides ReadOnly Property EnablePasswordReset() As Boolean
Get
End Get
End Property
Public Overrides ReadOnly Property EnablePasswordRetrieval() As Boolean
Get
End Get
End PropertyPublic Overrides Function FindUsersByEmail(ByVal emailToMatch As String, ByVal pageIndex As Integer, ByVal pageSize As Integer, ByRef totalRecords As Integer) As System.Web.Security.MembershipUserCollection
End FunctionPublic Overrides Function FindUsersByName(ByVal usernameToMatch As String, ByVal pageIndex As Integer, ByVal pageSize As Integer, ByRef totalRecords As Integer) As System.Web.Security.MembershipUserCollection
End FunctionPublic Overrides Function GetAllUsers(ByVal pageIndex As Integer, ByVal pageSize As Integer, ByRef totalRecords As Integer) As System.Web.Security.MembershipUserCollection
End Function
Public Overrides Function GetNumberOfUsersOnline() As Integer
End Function
Public Overrides Function GetPassword(ByVal username As String, ByVal answer As String) As String
End FunctionPublic Overloads Overrides Function GetUser(ByVal username As String, ByVal userIsOnline As Boolean) As System.Web.Security.MembershipUser
End FunctionPublic Overloads Overrides Function GetUser(ByVal providerUserKey As Object, ByVal userIsOnline As Boolean) As System.Web.Security.MembershipUser
End Function
Public Overrides Function GetUserNameByEmail(ByVal email As String) As String
End Function
Public Overrides ReadOnly Property MaxInvalidPasswordAttempts() As Integer
Get
End Get
End Property
Public Overrides ReadOnly Property MinRequiredNonAlphanumericCharacters() As Integer
Get
End Get
End Property
Public Overrides ReadOnly Property MinRequiredPasswordLength() As Integer
Get
End Get
End Property
Public Overrides ReadOnly Property PasswordAttemptWindow() As Integer
Get
End Get
End PropertyPublic Overrides ReadOnly Property PasswordFormat() As System.Web.Security.MembershipPasswordFormat
Get
End Get
End Property
Public Overrides ReadOnly Property PasswordStrengthRegularBLOCKED EXPRESSION As String
Get
End Get
End Property
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 ReadOnly Property RequiresUniqueEmail() As Boolean
Get
End Get
End Property
Public Overrides Function ResetPassword(ByVal username As String, ByVal answer As String) As String
End Function
Public Overrides Function UnlockUser(ByVal userName As String) As Boolean
End FunctionPublic Overrides Sub UpdateUser(ByVal user As System.Web.Security.MembershipUser)
End Sub
Public Overrides Function ValidateUser(ByVal username As String, ByVal password As String) As BooleanDim 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 TryEnd Function
End Class
|
|