Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check for a U+P in a file?? Please HELP! 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I would like to make a program that when executed it checks if a certain file exists with a username + password in it. If this value is true then it asks the user to login and compares the answer to the u+p in the file.

If the file doesn't exist or there just isn't a u+p in it, then it will open a form that asks the user for a u+p of his choice. Then it saves to the file.

Next time the user logs on, he can login with the u+p that he specified previously.

If anyone can help or give me a Source file it would be greatly appreciated.
Thanx
 
Check if a file exist:
strChckFile = Dir("d:\u&p.txt")
If strChckFile <> &quot;&quot; Then
' the file exists

read a file:
Open &quot;D:\u&p.txt&quot; For Input As #1
Line Input #1, strUsername
Line Input #1, strPassword
close #1

Write username and password in a file:

Open &quot;D:\u&p.txt&quot; For Output As #1
Print #1, strUsername
Print #1, strPassword
Close #1
End Sub

 
THANK YOU VERY, VERY, VERY MUCH !!!!

==== Hail King HARMEIJER ====

Thank you very much for your help. I got it working. I really appreciate it.

Thank you



 
It might be simpler to let Windows handle the passwords. Try this in your log-in form:
Add two text boxes (txtUserName and txtPassword) and a command button (cmdVerify).
The user will be forced to enter his Windows password in order to use your application. If you want to restrict access to certain users you can save the names to a file and then check the value of the GetWindowsLoginUserID function against that list to abort application start-up prior to loading the log-in form.
[tt]
Private Declare Function GetUserName Lib &quot;advapi32.dll&quot; Alias _
&quot;GetUserNameA&quot; (ByVal lpBuffer As String, _
nSize As Long) As Long

Private Declare Function WNetVerifyPassword Lib &quot;mpr.dll&quot; Alias _
&quot;WNetVerifyPasswordA&quot; (ByVal lpszPassword As String, _
ByRef pfMatch As Long) As Long

Private Function GetWindowsLoginUserID() As String
Dim rtn As Long
Dim sBuffer As String
Dim lSize As Long
sBuffer = String$(260, Chr$(0))
lSize = Len(sBuffer)
rtn = GetUserName(sBuffer, lSize)
If rtn Then
sBuffer = Left$(sBuffer, lSize)
If InStr(sBuffer, Chr$(0)) Then
sBuffer = _
Left$(sBuffer, InStr(sBuffer, Chr$(0)) - 1)
End If
GetWindowsLoginUserID = sBuffer
Else
GetWindowsLoginUserID = &quot;&quot;
End If
End Function

Private Function VerifyWindowsLoginUserPassword _
(ByVal Password As String) As Boolean
Dim rtn As Long, Match As Long
rtn = WNetVerifyPassword(Password, Match)
If rtn Then
VerifyWindowsLoginUserPassword = False
Else
VerifyWindowsLoginUserPassword = (Match <> 0)
End If
End Function

Private Sub cmdVerify_Click()
If VerifyWindowsLoginUserPassword(txtPassword.Text) = True Then
x = MsgBox(&quot;Correct password. Continue.&quot;, vbOKOnly)
Unload Me
Else
x = MsgBox(&quot;Incorrect password!&quot;, vbCritical)
txtPassword.SetFocus
End If
End Sub

Private Sub Form_Load()
txtUserName.Text = GetWindowsLoginUserID
txtUserName.Enabled = False
End Sub
[/tt]

There are certainly better ways to handle application user identification but this is probably the simplest and most foolproof. It only fails when an authorized user trys to access your application without logging on to Windows first.

VCA.gif

Alt255@Vorpalcom.Intranets.com​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top