Jul 20, 2008

Simple Login In Visual Basic 6 - user interaction example trough login programm

Free Web Hosting, No Ads > CONTRIBUTE > Tutorials

free web hosting

Simple Login In Visual Basic 6 - user interaction example trough login programm

kitty
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
If you don't see it, you will need to type it by hand. You will only need to type the first line (Private Sub Form_Load()), the last line, visual basic will add automaticaly (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
This part is simple, we only prepare variables for use (I know there is more technical explanation for this, but I can't remember laugh.gif).

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 wink.gif). In that file, write the username you want, and in next line, write the password. Now, add the following code:
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
First, we ask a user, to enter his full name, so we can know how to address him/her. If the user doesn't enter his/hers name, we will tell him he/she needs to enter it, or to quit the program. I believe the code is very self explainatory.

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
This is basicaly the same thing we used for prompting for full name, just with different variables.

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, I guess you noticed this is the same thing I used in two earlier segments of programm. I was told it can be done with functions or subs, but I haven't learned it yet smile.gif I guess I'll post another tutorial when I learn how to do that wink.gif

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
Here, we check if saved username is the one entered, and if the saved password is the one entered. If they match, we allow the user to access the programm, if not, we tell him/her there is an error, and exit the programm.

I learned this recently, and I hope I passed that knowledge to some of you..

 

 

 


Reply

masterio
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 biggrin.gif

Reply

ghostrider
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]









 

 

 


Reply

masterio
Very very good, I will try it soon. Thanks ghost!

Reply

iGuest
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

Reply

iGuest
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

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. visual basic 6 login box - 4.37 hr back. (1)
  2. code login visual basic 6.0 - 7.28 hr back. (1)
  3. how can i apply my logon system in vb6 in my computer - 7.93 hr back. (1)
  4. vb6 login website - 8.09 hr back. (1)
  5. basic - 9.03 hr back. (1)
  6. visual basic 6 log in form - 10.57 hr back. (1)
  7. vb 6 read a specific record in a database sample code - 12.83 hr back. (2)
  8. make user log in visual basic - 14.06 hr back. (1)
  9. form login vb 6.0 - 15.55 hr back. (1)
  10. login tutorial vb6 - 24.08 hr back. (1)
  11. user name and password visual basic example - 24.73 hr back. (1)
  12. logon system by using visual basic 6 - 26.48 hr back. (1)
  13. example vb login - 27.08 hr back. (2)
  14. simple vb coding for login form - 29.78 hr back. (1)
Similar Topics

Keywords : simple, login, visual, basic, 6, user, interaction, trough, login, programm

  1. Ftp In Visual Basic 6.0
    Start making your FTP client using VB6 (0)
  2. User Permission Function [php]
    Determining User Permissions (3)
    There have been several recent request for methods to restrict access to various pages on a web-site
    based on User Permissions in sites that have a Login System in place. Here is some code showing one
    method to restrict access by providing a sub-set of your site's links based on the User's
    permissions. In this demonstration, I have defined a string for each 'level of user'
    determining which set(s) of links they can view on your site. Normal MySql procedure would be to
    read the User's permission level from a record in the database. For the purpose of ....
  3. To Automatically Run Command When Login / Logoff
    (3)
    In case that you need login and / or logoff to execute some commands. You could do this with GPO
    login / logoff function. Here is step: 1.) Choose Start Menu -> Run -> type in gpedit.msc 2.)
    Expand User -> Windows Settings ->Script ( Logon / Logoff ) 3.) Double-Click either one and a dialog
    displayed 4.) Click the add button and then browse the command files that you wish to executed. The
    Script Parameters allowed you to pass any extra parameters to the command or applications. Click OK
    button. 5.) You command now should displayed on Name / Parameters List Box. Click O....
  4. Simple Php Login And Registration System
    (10)
    Hello. This is my first web tutorial ever. This is basically a simple register and login script.
    Yes, I know it’s a bit rubbish but I’m quite new to PHP/MySQL. Here’s the register form. This can
    be any file extension you like. I’d recommend calling it register.html . CODE
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html
    xmlns="http://www.w3.org/1999/xhtml"> <head> <meta
    http-equiv="Content-Type" content="text/ht....
  5. Simple User System
    php, mysql driven (19)
    Hey! Maybe you've seen my other tutorials...or my signature.. Anyways I'm going to show
    you how to make a system so users of your site could register accounts and you could have protected
    - user only - pages on your site /smile.gif" style="vertical-align:middle" emoid=":)" border="0"
    alt="smile.gif" /> Ok, so we start by creating a config.php file. CODE <?php
        $dbhost   = 'database host';     $dbname   = 'database name';
        $dbusername   = 'database username';     $dbuserpass = 'database pas....
  6. Flatfile User Login/signup
    Uses text files only (compatable with forums and message system) (24)
    With this tutorial, you will learn how to create a textfile login script. This user membership
    script is for use also with my forums and message system scripts. I will also give you the scripts
    to make it so that people can change their profiles. Ok, The first thing we need to do is make the
    database. To do this, create a blank text file called 'userdata.txt' , make sure it is ALL
    LOWER-CASE. Edit this file and put
    '**username|##|password|##|email|##|rank|##|userid|##|name|##|picture**'. This will not be
    used, however it will give you an idea of how the....
  7. Creating A Timer Program
    Using Visual Basic 2005 (8)
    This tutorial will explain how to create a basic timer using Visual Basic Express 2005. If you
    don't have it, it's free and you can dowload it from Microsoft's website. All you need
    is a few minutes to sit down and read this and a version of Visual Basic. OK, so what will this
    timer actually do? Well, you are able to enter a number of minutes and a message, and then click a
    button. Once the timer is up, your message pops up and you are reminded! So, basically it's
    a little reminder system. I use it to remind me when TV programmes start, when I have to....
  8. Creating A Simple Image Viewer
    Using Visual Basic 2005 Express Edition (3)
    I downloaded Microsoft's Visual Studio Express suite a few months ago, but only recently got
    around to installing it. I have been practising with Visual Basic and making some rather basic
    programs and utilities, but they contain most of the basic concepts. This tutorial will explain how
    to create a basic image viewer, and I will try to explain each step from beginning to end as clear
    as I can. To start you will need: Microsoft Visual Studio About 10-20 minutes free time OK,
    first open up the Visual Basic part of the Studio. I am using the 2005 Express version, so....
  9. How To Make A Web Browser
    Visual Basic 6 (48)
    This is a simple and specific tutorial on how to make a basic web browser in Visual Basic 6. Steps
    1-3 Create a new project, and then go to "Project" on the menu. Click components as shown in the
    following image. Find the component "Microsoft Internet Controls," check it, and click "Apply" and
    then "Close." Click the icon that was just added in the tools window, and draw a large sized
    window with it. This is going to be where you view webpages through your browser, so don't make
    it small, but leave room for buttons and other accessories. Steps 4-6 Make a t....
  10. Automatic Login
    in WinXP (5)
    Ever wanted to just turn on our computer and when you get back it's already on the desktop?
    (Rather then having to login at the welcome screen) Now some computer have this feature by default,
    but what if it gets broken, try this. On an Administrator account goto start >> Run, and type
    "control userpasswords2" (without the quotes) Uncheck the box that "Users must enter a Username and
    Password to use this computer", then press Ok. You will be prompted to enter a default user and
    their pasword, then next time you restart the computer it will automaticaly login to that....
  11. Bit Shifting In Vb
    Shifting bits in Visual Basic (0)
    This is for all Visual Basic programmers out there, who want to programm some form of encryption
    algorithm, or anything else that includes shifting bits left or right, for that matter. Most of you
    who have tried to accomplish this, know that Visual Basic doesn't have any function for bit
    shifting. And bit shifting si very usefull /smile.gif' border='0' style='vertical-align:middle'
    alt='smile.gif' /> Some of you probably know how to shift bits, but this tutorial is for those who
    don't know how to do it... Shifting bits is actualy easy, we use multiplication ....
  12. How To "lock Down" A Os X User Account
    Crude but effective way to maintain Macs (1)
    Here's a quick summary of how one can configure OS X for use in public labs running Panther
    (10.3). It should also work with Tiger (10.4) but I dunno. There may be better ways, but this is
    quick and cheap: 1. Install OS X fresh, or boot up your new Mac, and set the username to
    MacAdmin or the like. This is now the administrator account which users should never touch.
    Share this password only with trusted admins authorized to muck with critical systems. 2.
    Install all the software you expect anyone to need in the default folders (usually Applicat....
  13. Hiding User Account On Xp
    (0)
    Hopefully someone will find this useful. Ive done this on my machine as well. To a hide an account
    to display on the welcome screen of xp here is a nifty way: 1. Open regedit 2. Browse to
    Hkey_local_machine> software>microsoft>windows nt>winlogon>special Accounts>Userlist Here you will
    see a list of all accounts on XP which are hidden and dont display on welcome screen. Yes XP does
    create useless accounts as you see there. 3. Go on the right pane, right click, create a new dword
    value with its name as the exact username you want to hide and its value as "0" without t....
  14. How To: Change An Image When A User Clicks On It
    using both php and javascript (11)
    How To: Change An Image When A User Clicks On It using both php and javascript - a powerful
    combination I have seen quite a few how tos offering a method of doing this but none of which
    resembled my method of making use of both php and javascript. This code is fairly repetitive and
    most of the functions are easy to pick-up if you haven't heard of them before. Here it is...
    Create your two images. Call them anything you like, you'd just need to change their filenames
    in $imgano $imgayes. In fact with this script you can easily create more tha....
  15. How To Put A Phpbb Login Box On Your Main Site.
    Code and .php included!!! (18)
    I have included my coded file with this... Ok here is the code. CODE // //Create login area,
    replace the phpBB2 in /phpBB2/login.php with your forum's //directory // <form
    action="/phpBB2/login.php" method="post" target="_top"> <table
    width="25%" cellspacing="2" cellpadding="2" border="0"
    align="center">  <tr> <td align="left"
    class="nav"><a href="/phpBB2/index.php" class="nav">Prank Place
    Forum Index</a></td>....
  16. Php/mysql Login/register
    Tutorial for login with databases. (2)
    Start register code. Register.php CODE <form method=post
    action=register.php?action=register  name=s> <table>
    <tr><td>Username:</td><td><input type=text
    name=user></td></tr>
    <tr><td>Email:</td><td><input type=text
    name=email></td></tr>
    <tr><td>Pass:</td><td><input type=password
    name=pass></td></tr> <tr><td>Verify
    Pass:</td><td><input ....
  17. Complete Login And Registration System
    doesn't use mysql! (9)
    kLogin 0.1 QUOTE(readme.txt) Readme file to kLogin 0.1 To use the internet explorer fix:
    download the latest IE7 ZIP file
    (http://sourceforge.net/project/showfiles.php?group_id=109983&package_id=119707) Extract the ie7
    zip file to the root directory of your web server. Example, if you are using a unix/linux server,
    it's on "public_html/" or "home/public_html" Open kLogin.php file with your editor and edit the
    $info_text or $info_txt variable. Then, extract the kLogin.php file in to the root
    directory of your web server also. Just run kShoutBo....
  18. Multiple Admin Login (php)
    This is a script that doesnt requre SQL (3)
    first off make a login.html page Code: QUOTE Admin Login Username: Password:
    then make a check.php page Code: QUOTE $admin1 = "admin1"; //
    first admin username $adm_pass1 = "password1"; // first admin password $admin2 =
    "admin2"; // second admin username $adm_pass2 = "password2"; // second admin password
    if(($username == $admin1 && $password == $adm_pass1) || ($username ==
    $admin2 && $password == $adm_pass2)){ echo "Congratulations " . $_POST . " ....
  19. Php Simple Login Tutorial
    Learn how to make a simple login! (63)
    I have been quite busy lately, trying to design and code my site (far from done XD). And after
    having learned how to make a simple login, I will try to write my own tutorial, for you
    /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> the tutorial Step 1
    : The first step in designing a member system is to plan out exactly what you need. A common impulse
    among programmers is to jump right in and start coding. I'll be honest and admit that I'm
    guilty of this more so than anyone. However, since I'm in control of this conversation (y....
  20. Simple Visual Basic 6 Tutorial
    Tutorial 1: Msgbox (0)
    For this tutorial you will learn how to make a very simple, and basic program. Step one- Create a
    new form. Step two- Click the command button on the side and make two buttons. Step Three- Click
    on on of the command buttons you drew, and on the side there will be a menu. Change the caption to
    Button 1, and repeat the same with the other button, but the caption Button 2. Step four- Double
    click one of the buttons, and put in CODE Dim button button = MsgBox("What you want to
    say here", 65, "Title") Now change that code to what you want it ....
  21. Complete Login System
    With PHP + MYSQL (56)
    Its an complete login sistem made and tested by me and I think itwill be very usefull for people who
    are tryn to learn PHP. First, let's make register.php: CODE <?
    include("conn.php"); // create a file with all the database connections
    if($do_register){ // if the submit button were clicked if((!$name)
    || (!$email) || (!$age) || (!$login) ||
    (!$password) || (!$password2)){ print "You can't let
    any fields in blank....
  22. [tutorial] Visual Basic 6
    Adding Commas to Large Numbers (0)
    This isn't a very long tutorial. I get asked this often, so here is the solution. The following
    code will return a string containing a number that has commas appropriately placed: Code:
    myStringOrProperty = FormatNumber(3587532789053, 0) The second parameter (0) represents how many
    decimal places you want the returned number to go out to. Unless your number contains its own
    decimal, you probably don't want .00 at the end of every number you have. The above code would
    return: 3,587,532,789,053 This should make life easier for many.......
  23. [tutorial] Visual Basic 6
    Closing Programs Right, Why END is bad (2)
    This tutorial applies to all those people who insist upon using "End" to close their programs: End
    stops the program immediately without any thought as to what's going on - it's like a high
    speed train hitting a brick wall. It can cause unwanted errors and is bad programming practice in
    general. END gets rids of the form, but NOT its leftovers. This leaves a bunch of memory that will
    still be in use even after your program has supposedly closed. An object or variable won't be
    terminated properly - it's just not a graceful exit. The only time that it'....

    1. Looking for simple, login, visual, basic, 6, user, interaction, trough, login, programm

Searching Video's for simple, login, visual, basic, 6, user, interaction, trough, login, programm
advertisement



Simple Login In Visual Basic 6 - user interaction example trough login programm



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE