What's new

[VB] login system

  • Thread starter bob1337
  • Start date
  • Views 2,433
B

bob1337

Newbie
Messages
16
Reaction score
5
Points
45
Sin$
0
login system

hi was bored today so i decided to code a login system sample.
It requires a webserver & mysql database Of course you need VB6 to compile
It's pretty easy, so have a look at it and reply

#1 you need to add a Winsock to the Form
#2 add 2 Text boxs to the Form
#3 names Textbox1 txtUser
#4 names Textbox2 txtPass
#5 add a CommandButton to the Form
#6 add the code
#7 upload the php file
#8 get a webserver
#9 upload the database to mysql server
#10 login use User: test Pass: test

vb 6.0 code:
Code:
Option Explicit

Const HardwareID As String = "PEFPXG-37BANQ-OUgR26-PT02W2"

Private Sub Winsock1_Connect()

Dim sDaten As String
sDaten = "username=" & txtUser.Text & "&password=" & txtPass.Text & "&hardwareid=" & HardwareID


Dim postdaten As String
postdaten = postdaten & "POST /verify.php HTTP/1.1" & vbCrLf    'Path to Script
postdaten = postdaten & "Host: n01d.com" & vbCrLf                 'Host
postdaten = postdaten & "Content-Type: application/x-www-form-urlencoded" & vbCrLf
postdaten = postdaten & "Content-Length: " & Len(sDaten) & vbCrLf & vbCrLf
postdaten = postdaten & sDaten


Winsock1.SendData postdaten
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)

Dim sResponse As String
Winsock1.GetData sResponse


If InStr(1, sResponse, "Account valid.") <> 0 Then
Form2.Show
Unload Me
Else
MsgBox "Account invalid!"
End If
End Sub

Private Sub Command1_Click()
If txtUser.Text <> "" And txtPass.Text <> "" Then
Winsock1.Close
Winsock1.Connect
End If
End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Form_Load()
Winsock1.RemoteHost = "n01d.com"
Winsock1.RemotePort = 80
End Sub
php code file name verify.php:
Code:
<?
//login by bob at n01d.com


if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['hardwareid'])) {

//mysql db
$mysqlhost = "sql_host";         //MySQL-Host (connect "localhost")
$mysqluser = "sql_user";         //MySQL-User
$mysqlpwd = "sql_pass";          //MySQL-Password
$mysqldb = "sql_db";             //MySQL-Database

//mysql connect
$connection = mysql_connect($mysqlhost, $mysqluser, $mysqlpwd);
mysql_select_db($mysqldb, $connection);

$daten = mysql_query("Select * from login where username= '".$_POST['username']."'");
$row = mysql_fetch_assoc($daten);

if ($row["login"] == "true"){

if ($row["hwid"] == $_POST['hardwareid']){

if (($_POST['username'] == $row['username']) && ($_POST['password'] == $row['password'])) {
echo "Account valid.";
} else {
echo "Account invalid.";
}
}
}
}

?>
mysql database:
Code:
-- phpMyAdmin SQL Dump
-- version 2.11.4
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Feb 22, 2010 at 09:34 PM
-- Server version: 5.0.51
-- PHP Version: 5.2.5

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `login`
--

-- --------------------------------------------------------

--
-- Table structure for table `login`
--

CREATE TABLE IF NOT EXISTS `login` (
`username` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`hardwareid` varchar(255) NOT NULL,
`login` varchar(6) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `login`
--

INSERT INTO `login` (`username`, `password`, `hardwareid`, `login`) VALUES
('test', 'test', 'PEFPXG-37BANQ-OUgR26-PT02W2', 'true');
by [email protected]
 
DrXthirst

DrXthirst

Join Date: March 2006
Seasoned Veteran Grammar Nazi Grizzled Veteran
Messages
1,116
Reaction score
334
Points
195
Sin$
7
Re: login system

Mind doing a C# version, please, kind sir?
 
sgt frankieboy

sgt frankieboy

Enthusiast
Messages
722
Reaction score
140
Points
125
Sin$
7
Re: login system

mind doing a VB.net version? Nobody use VB6 around here(I think)

But Looking at the PHP code Well done :thumbup:
 
SotG Caboose

SotG Caboose

Getting There
Messages
1,448
Reaction score
687
Points
230
Sin$
0
Re: login system

Converted to C# for you guys.
Code:
string HardwareID = "PEFPXG-37BANQ-OUgR26-PT02W2";

private void Winsock1_Connect(object sender, EventArgs e)
{    
string sDaten = "username=" + txtUser.Text + "&password=" + txtPass.Text + "&hardwareid=" + HardwareID;

string postdaten;
postdaten += "POST /verify.php HTTP/1.1\n"  ;  //Path to Script
postdaten += "Host: n01d.com\n";                //Host
postdaten += "Content-Type: application/x-www-form-urlencoded\n";
postdaten += "Content-Length: " + sDaten.Length.ToString() + "\n\n";
postdaten += sDaten;


Winsock1.SendData(postdaten);
}

private void Winsock1_DataArrival(long bytesTotal)
{   
string sResponse = "";
Winsock1.GetData(ref sResponse);   //might be wrong
// sResponse = Winsock1.GetData(); // try this if ^ doesn't work
if (!sResponse.Contains("Account Invalid"))
{
Form2 frm2 = new Form2();
frm2.Show();
this.Close();
}
else
MessageBox.Show("Account Invalid");
}

private void Command1_Click(object sender, EventArgs e)
{
if (txtUser.Text != "" && txtPass.Text != "")
{
Winsock1.Close();
Winsock1.Connect();
}
}

private void Command2_Click(object sender, EventArgs e)
{
this.Close();
}

private void Form_Load(object sender, EventArgs e)
{
Winsock1.RemoteHost = "n01d.com";
Winsock1.RemotePort = 80;
}
 
DrXthirst

DrXthirst

Join Date: March 2006
Seasoned Veteran Grammar Nazi Grizzled Veteran
Messages
1,116
Reaction score
334
Points
195
Sin$
7
Re: login system

Thank you! :biggrin:
Now to figure out how to implement it into my program.
 
K

KyleBoyer

Enthusiast
Messages
253
Reaction score
42
Points
85
Sin$
0
Can someone please figure out how to make this work now? When I attempt to do the VB code, it always says "Account Invalid." So, then I had it show the sResponse string, and this is what it returns back to be:

Code:
HTTP/1.1 200 OK
Server: nginx/0.8.52
Date: Sat, 01 Jan 2011 01:01:15 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive

1e1
<html><head><title>n01d.com</title></head><frameset rows='100%, *'
frameboarder=no framespacing=0 border=0><frame 
src= "http://66.197.151.197/noidentification.html" name=mainwindow 
frameborder=no framespacing=0 marginheight=0 
marginwidth=0></frame></frameset><noframes><h2>Your browser does not 
support frames. We recommend upgrading your 
browser.</h2><br><br><center>Click <a 
href="http://66.197.151.197/noidentification.html">here</a> to enter the 
site.</center></noframes></html>
0



So I was hoping someone could update the code to make a remote login...
 
Top Bottom
Login
Register