Reputation: 5
So, this my code. It gets only the first document. But what I want to do is read a specific document. The view is a collection of usernames and passwords. So, for example : The username is in the 5th document, then the program will scan the view until it finds the right document. Sorry for my poor explanation. I hope you understand my problem.
On Error Goto e
Dim db As NotesDatabase
Dim view As NotesView
Dim results As Variant
Dim cmd As String
Dim d As NotesDocument, flag As Integer, upw As String, uname As String
Set db = source.Database
uname = Inputbox("Enter Username")
Set view = db.GetView("Registration View")
Set d = view.GetFirstDocument()
'cmd = {@DbLookup("";"48257E00:00089AF5";"RegView";1)}
'results = Evaluate(cmd)
Dim pw As String, un As String
'Forall Username In results
' Msgbox username(1)
'End Forall
If Not d Is Nothing Then
un = d.userfield(0)
pw = d.passfield(0)
If un <> uname Then
Msgbox "Username invalid!"
End If
If un = uname Then
upw = Inputbox("Enter Password")
If pw <> upw Then
Msgbox "Password invalid!"
End If
If pw = upw Then
Msgbox "Log In succesful!"
flag = 1
End If
End If
End If
If flag <> 1 Then Call source.Close()
Exit Sub
e:
Print Error, Erl
Upvotes: 0
Views: 675
Reputation: 12080
Of course you could cycle through the complete view and compare each single entry, but that will be quite slow. In your code the complete "cycling" is missing. You would need to use a do - while loop to run through all entries in the view:
Set d = view.GetFirstDocument()
Do
un = d.userfield(0)
pw = d.passfield(0)
'- here comes the rest of your code, if password is right - exit
If flag = 1 then exitLoop = True
Set d = view.GetNextDocument( d )
if d is Nothing then exitLoop = True
Loop until exitLoop
But this is quite inefficient. If your view is sortey by username (if not, create one that is), then use getDocumentbyKey as suggested by Thomas.
Set d = view.GetDocumentByKey( uname )
If not d is Nothing then
un = d.userfield
The question is WHY would one do something like this: Notes / Domino has a great security concept and saving all usernames and passwords in a view, where everybody can simple read the passwords by checking the document properties is -sorry to say- stupid and does not give you even one more bit of security...
Upvotes: 0
Reputation: 548
You can create a view with the first column userfield and the second column passfield. The first column has to be sorted.
In your code build an array of uname and upw
Dim strSearch (0 to 1) as String
Dim viewSearch as NotesView
Dim doc as NotesDocument
viewSearch = db.getView("YourSearchView")
strSearch(0) = uname
strSearch(1) = upw
Set doc = db.getDocumentByKey(strSearch, true)
If(Not doc is nothing)Then
Print "Login successfull"
Else
Print "Wrong username or password"
End if
If you want to use a two step check of username and then password you can create two search views and use the first for check if the username exists and the second for checking the given username and password.
Upvotes: 0
Reputation: 3636
Instead of using view.getFirstDocument you should use view.getDocumentByKey(uname,true) which return the document with the key uname in the first column in the view
Make sure the first column In the view is set to sorted
If no document is found using the key then getDocumentByKey returns nothing
Upvotes: 3