borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (sharing database)Next Topic (VB4.0 - Trouble with MDB, Visdata, Datman) New Topic New Poll Post Reply
AndreaVB Forum : Database : Help creating a login program
Poster Message
Outsider
Level: Guest


icon Help creating a login program

i am writing a simple login code for a program where the username and password should be checked for validatitiy on a mysql database.. i can connect to the database but i cant figure out how to validate the username and password .. using an if statement   can someone help me with this please !

06-11-2003 at 04:30 AM
| Quote Reply
Shady
Level: VB Guru


Registered: 08-07-2002
Posts: 305
icon Re: Help creating a login program

Hi there,

Right I have tried the following code on my PC and it works fine, so here goes.

Create a MYSQL database called LOGIN, with a table called DETAILS and a field called NAME.

I have assumed there is no password on the MySQL database.

OK, next create a form with a button and a text box, then paste the following code underneath the command button:-

'Create connections
Dim ADOsqlCON As ADODB.Connection
Dim ADOsqlRS As ADODB.Recordset
Set ADOsqlCON = New ADODB.Connection
Set ADOsqlRS = New ADODB.Recordset
    
    'Log into MYSQL Dbase
    ADOsqlCON.CursorLocation = adUseClient
    ADOsqlCON.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _
            & "SERVER=andreavb.ipowermysql.com;" _
            & "DATABASE=login;" _
            & "UID=root;" _
            & "PWD=;"
        
'Open Recordset and select all records
ADOsqlCON.Open

ADOsqlRS.Open "SELECT * FROM Details", ADOsqlCON, adOpenStatic, adLockOptimistic

'Count number of records held in database
SQL_Records = ADOsqlRS.RecordCount

'Begin Loop to cycle through all records
For x = 1 To SQL_Records

'Check to see if text in text box matches current record
If ADOsqlRS!Name = Text1.Text Then
    'If it matches do this
    MsgBox "LOGIN", vbInformation
    GoTo Close_ADO
Else
    'Else move to the next record
    ADOsqlRS.MoveNext
End If

'Continue Loop
Next x

'If no match has been made do this
MsgBox "No LOGIN", vbExclamation

Close_ADO:

'Close conection
ADOsqlRS.Close

ADOsqlCON.Close


and hopefully there you have a very simple login program, you could also use this code to encrypt your entries within the database for extra security:-

'Decrypt text encrypted with EncryptText
Private Function DecryptText(strText As String, ByVal strPwd As String)
    Dim i As Integer, c As Integer
    Dim strBuff As String

#If Not CASE_SENSITIVE_PASSWORD Then

    'Convert password to upper case
    'if not case-sensitive
    strPwd = UCase$(strPwd)

#End If

    'Decrypt string
    If Len(strPwd) Then
        For i = 1 To Len(strText)
            c = Asc(Mid$(strText, i, 1))
            c = c - Asc(Mid$(strPwd, (i Mod Len(strPwd)) + 1, 1))
            strBuff = strBuff & Chr$(c And &HFF)
        Next i
    Else
        strBuff = strText
    End If
    DecryptText = strBuff
End Function



'Encrypt text
Private Function EncryptText(strText As String, ByVal strPwd As String)
    Dim i As Integer, c As Integer
    Dim strBuff As String

#If Not CASE_SENSITIVE_PASSWORD Then

    'Convert password to upper case
    'if not case-sensitive
    strPwd = UCase$(strPwd)

#End If

    'Encrypt string
    If Len(strPwd) Then
        For i = 1 To Len(strText)
            c = Asc(Mid$(strText, i, 1))
            c = c + Asc(Mid$(strPwd, (i Mod Len(strPwd)) + 1, 1))
            strBuff = strBuff & Chr$(c And &HFF)
        Next i
    Else
        strBuff = strText
    End If
    EncryptText = strBuff
End Function


its very simple to use, to encrypt your details use it like this

ADOsqlRS!Name = EncryptText((UserText), PassText)


and if you want to use it with the login code I provided just use this IF statement.

If ADOsqlRS!Name = EncryptText((UserText), PassText) Then


Hope that is of some use to you!

Regards

Shady

____________________________
I don't wanna die... but I ain't keen on livin' either

06-11-2003 at 01:35 PM
View Profile Send Email to User Show All Posts | Quote Reply
qwertypunk
Level: Big Cheese


Registered: 21-04-2006
Posts: 21
icon Re: Help creating a login program

Hey Shady can one create a login using MSAccess instead of MySQL

____________________________
There are two ways to make error free programs...only the third one works.

22-04-2006 at 08:33 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : Database : Help creating a login program
Previous Topic (sharing database)Next Topic (VB4.0 - Trouble with MDB, Visdata, Datman) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder