Computing.Net > Forums > Programming > Vb login form

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Vb login form

Reply to Message Icon

Name: junooni
Date: December 14, 2004 at 16:09:08 Pacific
OS: Windows Xp Pro Sp2
CPU/Ram: 1.7 Ghz 256 DRR
Comment:

hi to all....i am tring to create a login form in visual baisc...i have already done the froms and the buttons but a problem....i am using data file to store the usernames and passwords....i can succesfull do that by another form....but i cant seem to login properly for some reason...also if there is no username and password in the txt fields...the form still procceds.....
please help me out...its a ISU for school...bigg marks...
***CODE SHOWN BELOW***
Private Sub cmdLogin_Click()
Open App.Path & "\usr.txt" For Input As #1
If txtName.Text = usr Then
If txtPass.Text = pass Then
frmShop.Show
Else
MsgBox "UserName or Password not found"
End If

Else
MsgBox "Invaild username or password"
End If
Close #1
frmLogin.Hide
End Sub


thankz alot.....
u can contact me at code_247 (AT) hotmail.com
for further details about the program or for a zipped file of the pogram n all the forms......
thankz again....



Sponsored Link
Ads by Google

Response Number 1
Name: Chi Happens
Date: December 15, 2004 at 15:05:53 Pacific
Reply:

Option Explicit
Private MainPath As String
Private Type UNPW_STRUCT
UName As String
PWord As String
End Type
Private UNPW() As UNPW_STRUCT
Private MaxUNPW As Long
Private Sub cmdLogin_Click()
Select Case TryLogin(txtName.Text, txtPass.Text)
Case 0 ' Everythings Ok
Me.Hide
frmShop.Show
Case 1 ' User Name Not Valid
MsgBox "User Name Not Valid", vbOKOnly, "Login Denied"
Case 2 ' Password Not Valid
MsgBox "Password Not Valid", vbOKOnly, "Login Denied"
End Select
End Sub
Private Function TryLogin(ByVal UName As String, ByVal PWord As String) As Long
Dim ReturnValue As Long ' Value to return
Dim t As Long ' a counter variable
Dim FoundUname As Boolean ' flag
Dim FoundPword As Boolean ' flag

ReturnValue = 3 ' set to unspecified error
FoundUname = False
FoundPword = False

If LoadUNPWs() Then
For t = 0 To MaxUNPW - 1
If UCase(UName) = UCase(UNPW(t).UName) Then ' non case sensitive...remove ucase if you want it to be
FoundUname = True
If UCase(PWord) = UCase(UNPW(t).PWord) Then ' non case sensitive...remove ucase if you want it to be
FoundPword = True
ReturnValue = 0 ' done
Exit For
End If
End If
Next t

If Not FoundUname Then
ReturnValue = 1 ' ooh bab uname
ElseIf Not FoundPword Then
ReturnValue = 2 ' ooh bad pword
End If
End If

TryLogin = ReturnValue
End Function
Private Function LoadUNPWs() As Boolean
Dim Success As Boolean ' Return Value
Dim FileSpec As String ' Our filespec
Dim FP As Long ' the File Pointer
Dim FileBody As String ' holds the file doby
Dim FileLine As String ' holds a line
Dim P As Long ' positional item
Dim FSO As Object ' File System Object

Set FSO = CreateObject("Scripting.FileSystemObject") ' make one

Success = True ' set initial return value to true

FileSpec = App.Path ' Set Filespec to app.path
' Check for trailing paddy
If Right(FileSpec, 1) <> "\" Then
FileSpec = FileSpec & "\"
End If
FileSpec = FileSpec & "usr.txt" ' add text file

If FSO.FileExists(FileSpec) Then

FP = FreeFile() ' now get free file pointer

Open FileSpec For Input As #FP ' Open the file

FileBody = Input(LOF(FP), #FP) ' load the whole thing
Close #FP ' close the file

' My File Looks Like This: (un pw separated by pipe)
' USERNAME|PASSWORD
' USERNAME|PASSWORD
' USERNAME|PASSWORD
' USERNAME|PASSWORD

MaxUNPW = 0 ' initialize our variable
ReDim UNPW(1) As UNPW_STRUCT ' clear it out

Do While Len(FileBody) > 0 ' loop for loading un/pws
P = InStr(1, FileBody, vbCrLf) ' find end of line
If P > 0 Then
FileLine = Left(FileBody, P - 1) ' get a line
FileBody = Mid(FileBody, P + 2, Len(FileBody)) ' remove that line
Else
FileLine = FileBody ' get the whole thing
FileBody = "" ' delete it all
End If

P = InStr(1, FileLine, "|") ' find out pipe
If P > 0 Then
MaxUNPW = MaxUNPW + 1
ReDim Preserve UNPW(MaxUNPW) As UNPW_STRUCT ' preserve it but make it bigger
UNPW(MaxUNPW - 1).UName = Left(FileLine, P - 1) ' add the name
UNPW(MaxUNPW - 1).PWord = Mid(FileLine, P + 1, Len(FileLine)) ' add the password
Else
MsgBox "Authentication File Is Not Correct Format", vbOKOnly, "Fatal Error"
Success = False
End If
Loop
Else
MsgBox "Authentication File Not Found.", vbOKOnly, "Fatal Error"
Success = False
End If

Set FSO = Nothing ' delete the object
LoadUNPWs = Success
End Function


Enjoy,
Chi

"They mostly come at night...mostly"


0

Response Number 2
Name: Taiwo Olumide
Date: December 22, 2004 at 08:23:50 Pacific
Reply:

I am sure that whe you read in the pas word from the data file or external file you used a string variable. Understans that texts are not strings therefore you have to convert that txtName.Text to string by using Cstr(txtName.Text).

That is you can use

if Cstr(txtName.Text)=usr then the conditions continues.

Olumide abayomide@hotmail.com

the world


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Vb login form

How to use CRViewer in a VB child form www.computing.net/answers/programming/how-to-use-crviewer-in-a-vb-child-form/1451.html

Login form in vb www.computing.net/answers/programming/login-form-in-vb/10277.html

VB.net form parsing with html www.computing.net/answers/programming/vbnet-form-parsing-with-html/12581.html