[Guide] Visual Basic 2008 - Login system where everyone can get in. -
07-05-2008
Login System
-By Caroe
DESIGN
1. First off all you make you program, new you make a new form (in my case this form is form 2)
2. Now you create 2 labels, called "Username" and "Password" and 2 buttons called "Login" and "Create Account"
3. Now you create 2 Textboxes and place Username over one of them and Password over the other one.
4. Place "Login" Button just under the textboxes and Labels, and "Create Account" button under "Login" button.
5. Under "Create Account" button make a new button called "Delete Account"
CODING
FORM 1
1. go to you normal program (Form 1) and make everything set to "Visible = False"
the make a button called "Login" and write in it
Code:
Form2.show()
also if the login thing is in Form 2 else set it to the form it is
FORM 2
1. Press on "Create Account" button and write
Code:
If Textbox1.text = "" or Textbox2.text = "" Then
MsgBox("Both your Username and Password have to be atleast 1 letter")
Else
My.computer.filesystem.createfile("C:\Username.txt", Textbox1.text, False)
My.computer.filesystem.createfile("C:\Password.txt", Textbox2.text, False)
My.computer.filesystem.createfile("C:\Account.txt", "", False)
2. Press on "Login" button and write
Code:
Dim User$, Pw$
User = My.computer.filesystem.readalltext("C:\Username.txt")
Pw = My.computer.filesystem.readalltext("C:\Password")
if Textbox1.text = User and Textbox2.text = Pw Then
Form1.show()
Form1.button1.visble = True
The thing in red can be changed. if you also want button 2 to be visible after login then write the same just with button2 instead of button1.
Button1 = "Login" Button, else change the code
Button2 = "Create Account" Button, else change the code
Button3 = "Delete Account" Button, else change the code
Other
Else, if you want to see mine you can download it here :
Download : [Only registered and activated users can see links. ]
it has alot more features, and are way better. but you can look at it and see if you can make the same
I love this thank you for making it! Now I's are smarter with the coding!
I'll give +rep soon as I can
Edit I tested out yours first but there are a couple of errors in the program!
Code:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.UnauthorizedAccessException: Access to the path 'C:Username.txt' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.StreamWriter.CreateFile(String path, Boolean append)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding)
at Microsoft.VisualBasic.FileIO.FileSystem.WriteAllText(String file, String text, Boolean append, Encoding encoding)
at Microsoft.VisualBasic.MyServices.FileSystemProxy.WriteAllText(String file, String text, Boolean append)
at Login.Form2.Button2_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1434 (REDBITS.050727-1400)
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
Login
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Users/Merritt-PC/Desktop/Login.exe
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 8.0.0.0
Win32 Version: 8.0.50727.1434 (REDBITS.050727-1400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1434 (REDBITS.050727-1400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1434 (REDBITS.050727-1400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1434 (REDBITS.050727-1400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Runtime.Remoting
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1434 (REDBITS.050727-1400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
Last edited by Fireking300; 08-02-2008 at 07:05 AM.
Need help with code for creating files
If UsernameTextBox.Text = "" Then
MsgBox("Please enter a valid Username")
Else
My.Computer.FileSystem.CreateFile("C:\Random\random.txt")
My.computer.filesystem.createfile doesnt work the .createfile is not a member of that group it says.
You don't need the ".Createfile" at all, just use a StreamWriter. It will create the file for you once you write some lines.
This is how I manage files with VB.NET
Just make sure that you
Code:
Imports System.IO
Writing:
Code:
Private Sub WriteSomething(ByVal filename As String)
If File.Exists(filename) Then
File.Delete(filename)
End If
Dim filewriter As New StreamWriter(filename)
filewriter.WriteLine("line 1")
filewriter.WriteLine("line 2")
filewriter.Flush()
filewriter.Close()
End Sub
Reading:
Code:
Private Sub ReadStuff(ByVal filename As String)
Dim tempstring As String = ""
Dim temparray(0) As String
If File.Exists(filename) Then
Dim filereader As New StreamReader(filename)
Do Until filereader.EndOfStream = True
tempstring = filereader.ReadLine
If tempstring Is Nothing Then
Exit Do
Else
temparray(UBound(temparray)) = tempstring
ReDim Preserve temparray(temparray.Length)
End If
Loop
filereader.Close()
End If
End Sub
Soon you can find my projects at: www.termight.info