Link to home
Start Free TrialLog in
Avatar of iepaul
iepaulFlag for Ireland

asked on

detailsview authenticate user before insert

I want to authenticate a user before allowing them to insert a new record.  I have a funtion to check the username and password are correct which returns true or false.

The details view has four fields, projectnumber, customer, startdate, and user.  user is the user id of the authenticated user.

My first question is where do I ask for the password, can I add a password field to the details view or do I need some other mechanism?

Secondly I know there is an ItemInserting for the details view or an inserting event for the sqldatasource, which is best to use and how do I allow the insert if authenticated or block it if not?


    Function AuthenticateUser(ByVal path As String, ByVal user As String, ByVal pass As String) As Boolean
        Dim dirEntry As New DirectoryEntry(path, user, pass)
        Try
            Dim nat As Object
            'if the NativeObject can be created using those credentials
            'then they are valid.
            nat = dirEntry.NativeObject
            Return True
        Catch
            Return False
        End Try
    End Function
Avatar of ladarling
ladarling
Flag of United States of America image

My first question is where do I ask for the password, can I add a password field to the details view or do I need some other mechanism?
You could ask for the password in the detailsview.. And, In this scenario, I would create a class level boolean variable that indicated whether or not the user was authenticated.
Private UserIsAuthenticated As Boolean = False
And let your authentication function assign that value for the session. If you dont want that authentication to persist you would reset that value after the insert.
Secondly I know there is an ItemInserting for the details view or an inserting event for the sqldatasource, which is best to use and how do I allow the insert if authenticated or block it if not?
Basically, you just handle the ItemInserting event. The parameter object e will be a  DetailsViewInsertEventArgs
You can set its cancel property = True to abort the insert, based on whether the user is validated or not. Doing so in the page itself prevents you from having to rollback datasource changes.
Avatar of iepaul

ASKER

Do you have any samples of how this would work?  
ASKER CERTIFIED SOLUTION
Avatar of ladarling
ladarling
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial