|
|
|
|
![]() ![]() |
![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 83 Joined: 1-June 05 Member No.: 7,772 |
Post
#1
Jun 15 2005, 02:11 PM
First of all, I am NOT a programmer, this is something my friend taught me. It describes basic interaction with the user, while showing basic functionality of this simple programm. So, without further ado, we're off to the tutorial: First of all, start your visual basic, when prompted for new project, select Standard Exe. Next, we need to open code window, so we can start typing the program. This can be done in two ways, one is double clicking on the form, or selecting Code from View menu. If you double clicked on the form, you will see following text: CODE Private Sub Form_Load() End Sub Next, we need to declare variables we will use in our program. Here's the next piece of code: CODE Dim MyName As String ' This variable contains users full name Dim MyUName As String ' This variable contains users login name (username) Dim MyPass As String ' This variable contains users password Dim Response As Integer ' This variable contains users answers from message boxes Dim Saved_Name As String ' This variable contains saved username from file Dim Saved_Pass As String 'This variable contains saved password from file Now, we need to read username and password from the file. Now, for this example, we will use simple text file. You can create it using notepad (I don't think you need a tutorial on that CODE Open "pass.txt" For Input As #1 'we open file with data we need Line Input #1, Saved_Name ' We read username from file Line Input #1, Saved_Pass 'We read password from file Close #1 'we close the file Now that we have done this, we can proceed with basic interaction with the user: CODE Login_Name: MyName = InputBox("Please, enter Your name.", "Introduce yourself", "") If MyName = "" Then Response = MsgBox("To continue with the program, You need to introduce Yourself." & vbCrLf & "Do You wish to proceed with the programm?", vbCritical + vbYesNo, "Error") If Response = vbYes Then GoTo Login_Name If Response = vbNo Then MsgBox "We are sorry You do not wish to proceed." & vbCrLf & "We wish You a good day", vbInformation + vbOKOnly, "End" End End If End If Next, we will prompt for user name. This is the information that we need for successfull login. CODE Login_UName: MyUName = InputBox("Good day " & MojeIme & ", please, enter Your user name.", "Login", "") If MyUName = "" Then Response = MsgBox("To continue with the program, You need to enter username." & vbCrLf & "Do You wish to proceed with the programm?", vbCritical + vbYesNo, "Error") If Response = vbYes Then GoTo Login_UName If Response = vbNo Then MsgBox "We are sorry You do not wish to proceed." & vbCrLf & "We wish You a good day", vbInformation + vbOKOnly, "End" End End If End If Next, we ask the user to enter his/hers password, to authenticate into system: CODE Login_Pass: MyPass = InputBox("Please, enter a password for user name " & MyUName & ".", "Login", "") If MyPass = "" Then Response = MsgBox("To continue with the program, You need to enter Your password." & vbCrLf & "Do You wish to proceed with the programm?", vbCritical + vbYesNo, "Error") If Response = vbYes Then GoTo Login_Pass If Response = vbNo Then MsgBox "We are sorry You do not wish to proceed." & vbCrLf & "We wish You a good day", vbInformation + vbOKOnly, "End" End End If End If OK, we're almost done. All we have to do is check if username and passwords match, and if that is the case, we can proeed with programm. If not, we tell the user he/she made a mistake, and exit the programm. Here is the programm for that segment: CODE If (Saved_Name = MyUName) And (Saved_Pass = MyPass) Then MsgBox "Good day " & MyName & "." & vbCrLf & "Welcome to our programm, we wish You pleasant work.", vbInformation + vbOKOnly, "Welcome" Else MsgBox "We are sorry, username and/or password are not correct", vbCritical + vbOKOnly, "Error" End End If I learned this recently, and I hope I passed that knowledge to some of you.. |
![]() ![]() ![]() Group: Members
Posts: 49 Joined: 25-August 06 Member No.: 28,897 |
Post
#2
Aug 31 2006, 12:02 PM
Hey, Nice tutorial. But it seems only one user that can login!. It's better if we can use new way, so not only one user that can use the program. Anyone has an idea?, I'm not good in Visual Basic 6 |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 398 Joined: 9-June 06 From: Wisconsin Member No.: 24,924 |
Post
#3
Aug 31 2006, 11:02 PM
QUOTE Hey, Nice tutorial. But it seems only one user that can login!. It's better if we can use new way, so not only one user that can use the program. Anyone has an idea?, I'm not good in Visual Basic 6 I've used VB6 for 9 years. I'll post the code for how I would do it, however I'm sure there is more than just one way to create a simple login system. It'll just take a couple changes to the kitty's code to implement other users. We can copy the first part of kitty's code right into the form almost without changes. Here it is: CODE Dim MyName As String ' This variable contains users full name Dim MyUName As String ' This variable contains users login name (username) Dim MyPass As String ' This variable contains users password Dim Response As Integer ' This variable contains users answers from message boxes Dim Saved_Name() As String ' This variable contains saved username from file Dim Saved_Pass() As String 'This variable contains saved password from file The only real difference between my code and his/her's is that Saved_Name and Saved_Pass are now arrays. Arrays can hold more than one value, each value in an array is given a number. CODE Dim TotUser As Integer 'The total number of users Dim TempName As String 'For the name Dim TempPass As String 'For the pass TotUser = 1 Open "pass.txt" For Input As #1 'we open file with data we need Do Until EOF(1) Line Input #1, TempName ' We read username from file Line Input #1, TempPass ' We read password from file TotUser = TotUser + 1 'Add one to TotUser ReDim Preserve Saved_Name(1 To TotUser) 'Expand the array Saved_Name(TotUser) = TempName ReDim Preserve Saved_Pass(1 To TotUser) 'Expand the array Saved_Pass(TotUser) = TempPass Loop Close #1 'we close the file The ReDim statement resizes the array (creates more elements). The Preserve in the ReDim statement means to make sure the data originally in the array stays there. Without the preserve statement, only the last username and password would be in the array, all the others would be "" or NULL. The next bit of code stays the same. CODE Login_Name: MyName = InputBox("Please, enter Your name.", "Introduce yourself", "") If MyName = "" Then Response = MsgBox("To continue with the program, You need to introduce Yourself." & vbCrLf & "Do You wish to proceed with the programm?", vbCritical + vbYesNo, "Error") If Response = vbYes Then GoTo Login_Name If Response = vbNo Then MsgBox "We are sorry You do not wish to proceed." & vbCrLf & "We wish You a good day", vbInformation + vbOKOnly, "End" End End If End If So does the next bit CODE Login_UName: MyUName = InputBox("Good day " & MojeIme & ", please, enter Your user name.", "Login", "") If MyUName = "" Then Response = MsgBox("To continue with the program, You need to enter username." & vbCrLf & "Do You wish to proceed with the programm?", vbCritical + vbYesNo, "Error") If Response = vbYes Then GoTo Login_UName If Response = vbNo Then MsgBox "We are sorry You do not wish to proceed." & vbCrLf & "We wish You a good day", vbInformation + vbOKOnly, "End" End End If End If and the next bit CODE Login_Pass: MyPass = InputBox("Please, enter a password for user name " & MyUName & ".", "Login", "") If MyPass = "" Then Response = MsgBox("To continue with the program, You need to enter Your password." & vbCrLf & "Do You wish to proceed with the programm?", vbCritical + vbYesNo, "Error") If Response = vbYes Then GoTo Login_Pass If Response = vbNo Then MsgBox "We are sorry You do not wish to proceed." & vbCrLf & "We wish You a good day", vbInformation + vbOKOnly, "End" End End If End If Finally something actually changes!! CODE Dim i As Integer 'For the For Next Loop For i = 1 To TotUser 'Check every user. If (Saved_Name = MyUName(i)) And (Saved_Pass = MyPass(i)) Then MsgBox "Good day " & MyName & "." & vbCrLf & "Welcome to our program, we wish You pleasant work.", vbInformation + vbOKOnly, "Welcome" Exit sub 'You are logged in! Else If i = TotUser Then MsgBox "We are sorry, username and/or password are not correct", vbCritical + vbOKOnly, "Error" End End If End If Next i Place all this code together and it will work fine! Feel free to PM me with any questions you may have. [code] |
![]() ![]() ![]() Group: Members
Posts: 49 Joined: 25-August 06 Member No.: 28,897 |
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 5,876 Joined: 21-September 07 Member No.: 50,369 |
Post
#5
Feb 17 2008, 02:26 PM
internet cafe.. Simple Login In Visual Basic 6 How can I make a program with log-in log-out in my internet cafe using vb6? Also a time code... -question by camille |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 5,876 Joined: 21-September 07 Member No.: 50,369 |
Post
#6
Mar 19 2008, 10:25 AM
How to prevent multiple user login using one account in VB Simple Login In Visual Basic 6 I am writing a VB 6 program that shd run on the network. A user has to login before using the program. Now, I want to prevent multiple user login using one user account. It shouldn't allow or prevent a user to login whilst his/her account is in use. I am using MS SQL Server 2000 Database. Please, can anyone help me with this? I would be very grateful if you could help me with this. -question by King Acheampong |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 5,876 Joined: 21-September 07 Member No.: 50,369 |
Post
#7
Jul 25 2008, 05:11 AM
Sub programs Simple Login In Visual Basic 6 Replying to kitty If you type Sub the name of the sub program and press enter you have a sub program. Then all you have to do is put in the code. Example Sub Celebrate() Label1.Visible = False ImgDefence.Visible = False Cls BackColor = QBColor(15) ForeColor = QBColor(12) FontSize = 72 FontName = "Times New Roman" FontItalic = True CurrentX = 50 CurrentY = 150 Print "Victory To The Hearts!" Delay 5 End End Sub Hope I helped. -reply by Naomi |
![]() Group: Members
Posts: 1 Joined: 6-November 08 Member No.: 71,607 |
Post
#8
Nov 6 2008, 06:38 PM
Great code BUT i slightly changed it and i get the wrong password dude everytime and the pass.txt is so far only: test test So should be good enough i enclosed the code i used please help thanks Code : Private Sub Form_Load() Dim MyName As String ' This variable contains users full name Dim MyUName As String ' This variable contains users login name (username) Dim MyPass As String ' This variable contains users password Dim Response As Integer ' This variable contains users answers from message boxes Dim Saved_Name As String ' This variable contains saved username from file Dim Saved_Pass As String 'This variable contains saved password from file Open "pass.txt" For Input As #1 'we open file with data we need Line Input #1, Saved_Name ' We read username from file Line Input #1, Saved_Pass 'We read password from file Close #1 'we close the file Login_Name: MyName = InputBox("Skriv dit navn.", "Dit navn", "") If MyName = "" Then Response = MsgBox("Skriv dit navn eller det bliver værst for dig selv If Response = vbYes Then GoTo Login_Name If Response = vbNo Then MsgBox "Nå ikke!." & vbCrLf & "God dag til dig", vbInformation + vbOKOnly, "End" Form2.Visible = True End If End If Login_UName: MyUName = InputBox("Login " & MojeIme & ", Skriv dit brugernavn.", "Login", "") If MyUName = "" Then Response = MsgBox("Skriv dit brugernavn er du dum?." & vbCrLf & "Vil du fortsætte?", vbCritical + vbYesNo, "Error") If Response = vbYes Then GoTo Login_UName If Response = vbNo Then MsgBox "Synd for dig." & vbCrLf & "God dag til dig", vbInformation + vbOKOnly, "End" Form2.Visible = True End If End If Login_Pass: MyPass = InputBox("skriv password til brugernavn " & MyUName & ".", "Login", "") If MyPass = "" Then Response = MsgBox("Skriv dit password." & vbCrLf & "Vil du fortsætte?", vbCritical + vbYesNo, "Error") If Response = vbYes Then GoTo Login_Pass If Response = vbNo Then MsgBox "Synd for dig." & vbCrLf & "Hav en god dag", vbInformation + vbOKOnly, "End" Form2.Visible = True End If End If If (Saved_Name = MyUName) And (Saved_Pass = MyPass) Then End Else MsgBox "Nope dude, brugernavn og/eller password er forkert", vbCritical + vbOKOnly, "Error" Form2.Visible = True End If End Sub and a form1 with a button and code : Private Sub Command1_Click() Form2.Visible = True End Sub Private Sub Form_Load() App.TaskVisible = False (btw not full proff because the .exe name is still visible in processes not application any help on this too is appreciated or any coder can just close app from there :/) End Sub This post has been edited by dolph: Nov 6 2008, 06:43 PM |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 5,876 Joined: 21-September 07 Member No.: 50,369 |
Post
#9
May 19 2009, 05:51 PM
how to prevent mutiple logins Simple Login In Visual Basic 6 I am also beginner in vb6 but you can try to make an txtfile at login I an shared map and check if the file exists. And if you log out you delete it. You can use filesystemobject to do this. Just go to project,references and select windows script host object model. Here is the code to use it. (private declarations)
Dim f as new filesystemobject f.Deletefile(file) end sub I hope I helped you with this and sorry for my bad english I am dutch and 13 years old. |
![]() ![]() ![]() ![]() |
Post
#10
Jun 5 2009, 05:09 AM
Dang that would be complicated for beginners to understand, I just use a simple one that can easily be found out using olydbg but i still use it, it's just like a CODE if textbox1.text = "pass" then me.hide show.form2 But I like your style of thinking XD |
![]() ![]() |
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
14 | Spudd | 1,222 | 25th September 2009 - 08:24 PM Last post by: Spudd |
|||
![]() |
22 | Shackman | 37,714 | 27th October 2009 - 07:39 AM Last post by: NxTGaming |
|||
![]() |
12 | BooZker | 3,032 | 8th July 2006 - 07:50 AM Last post by: BooZker |
|||
![]() |
2 | zachtk8702 | 7,344 | 13th August 2004 - 04:26 PM Last post by: zachtk8702 |
|||
![]() |
0 | Jarlaxe | 1,539 | 23rd June 2007 - 11:13 AM Last post by: Jarlaxe |
|||
![]() |
2 | threepach | 2,167 | 19th February 2008 - 08:30 PM Last post by: threepach |
|||
![]() |
7 | truvu17 | 8,267 | 1st May 2006 - 03:20 PM Last post by: shadowx |
|||
![]() |
1 | pollux1er | 2,196 | 24th July 2007 - 11:13 PM Last post by: matak |
|||
![]() |
0 | Zenchi | 3,528 | 28th September 2004 - 03:35 AM Last post by: Zenchi |
|||
![]() |
3 | X3r0X | 5,334 | 28th September 2004 - 02:30 PM Last post by: X3r0X |
|||
![]() |
16 | Saint_Michael | 18,606 | 20th August 2009 - 06:09 PM Last post by: ENDY_JASMI |
|||
![]() |
8 | j-s | 5,492 | 30th September 2004 - 12:39 PM Last post by: Zenchi |
|||
![]() |
2 | Dawid | 5,240 | 14th October 2004 - 03:20 PM Last post by: ashiezai |
|||
![]() |
14 | Shadow | 16,380 | 2nd April 2009 - 07:06 AM Last post by: jesseruu |
|||
![]() |
6 | darkwarrior | 6,691 | 12th October 2004 - 12:23 AM Last post by: odomike |
|||
|
Open Discussion | Time is now: 22nd November 2009 - 06:51 AM |
Web Hosting Powered by ComputingHost.com.