3 Replies - 1133 Views - Last Post: 16 August 2014 - 02:51 AM Rate Topic: -----

#1 niks_noty12   User is offline

  • New D.I.C Head

Reputation: -6
  • View blog
  • Posts: 8
  • Joined: 14-May 10

How to do login without username, login with password only

Posted 15 August 2014 - 01:53 AM

How to do login without using username, login with password only using access database 2007 in VB.NET

Here my code using Button click event,
in this code using fill username and password click button to login,
but i need just put password to login no need username(without Username)


Imports System.Data
Imports System.Data.OleDb
Public Class Form5
    Inherits System.Windows.Forms.Form
    Dim mypath = Application.StartupPath & "\login.mdb"
    Dim mypassword = ""
    Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mypath & ";Jet OLEDB:Database Password=" & mypassword)
    Dim cmd As OleDbCommand

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Hide()
        Dim sql = "SELECT UserID ,PassID FROM MYTAB WHERE USERID='" & TextBox1.Text & "' AND PASSID='" & TextBox2.Text & "'"

        cmd = New OleDbCommand(sql, conn)
        conn.Open()
        Dim dr As OleDbDataReader = cmd.ExecuteReader

        Try
            If dr.Read = False Then
                MessageBox.Show("Authentication failed...")
                Me.Show()
            Else
                MessageBox.Show("Login successfully...")
                Dim frmDialogue As New Form11

                frmDialogue.ShowDialog()
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        conn.Close()
    End Sub
End Class



My login form Look like

Posted Image

Is This A Good Question/Topic? 0
  • +

Replies To: How to do login without username, login with password only

#2 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6833
  • View blog
  • Posts: 28,342
  • Joined: 12-December 12

Re: How to do login without username, login with password only

Posted 15 August 2014 - 02:31 AM

Where will the username come from? Environment.UserName? Or you might want to check Environment.UserDomainName.

(If so, then a minute searching would have uncovered these properties.)

This post has been edited by andrewsw: 15 August 2014 - 02:34 AM

Was This Post Helpful? 0
  • +
  • -

#3 thecoat   User is offline

  • D.I.C Addict

Reputation: 153
  • View blog
  • Posts: 537
  • Joined: 07-December 13

Re: How to do login without username, login with password only

Posted 16 August 2014 - 01:36 AM

Also worth noting the OleDbDataReader.Read method returns a boolean value to indicate if there are more rows left to read. If your query returns a user record, it will move to that record and report false, at which point you report an authentication failure. Instead of this use dr.HasRows.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6833
  • View blog
  • Posts: 28,342
  • Joined: 12-December 12

Re: How to do login without username, login with password only

Posted 16 August 2014 - 02:51 AM

I would use ExecuteScalar as you only need to confirm that a single row exists.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1