Results 1 to 4 of 4

Thread: Change Password in Database! PLEASE READ!

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    13

    Exclamation Change Password in Database! PLEASE READ!

    Hi there im new to visual basic and need ur help!

    Im trying to create a change password dialog with 3 textboxes. One for username, old password and new password. I've sucessfully connected to the MS Access 2000 database with MS jet 4.0 but dont the vb code to complete the dialog box. Inside the database each record represents one person. And theres two columns, 1 for username and password. They are called StaffUserName and StaffPassword. OK heres the scenario

    1. User enters their data into all 3 boxes
    2. vb using text in text box for username searches database for identical username in database. If not msgbox saying Username is incorrect
    3. database fixes onto that specific record.
    4. vb code saying if both username and password in textboxes matches database fields. StaffPassword changes to value in NewPassword textbox
    5. msgbox saying change complete

    If n e 1 can help me i would apreciate it very much. I need this for a college project! Thanx

  2. #2
    Member
    Join Date
    Nov 2003
    Location
    India
    Posts
    50
    Use the Following code
    It might work or else let me know it and post the codeusing VBcode tag
    VB Code:
    1. rs.open "Select * from Table where userName='" & txtuser & "' and password='" & txtPass & "'",connection,adopendynamic,adlockoptimistic
    2. if not rs.eof then
    3.         con.execute "Update table set password='" & txtpassword & "' where username='" & txtuser& "'"
    4. endif
    5. rs.close
    Knowledge is divine and he who pass the knowledge is ..........

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    13
    Na it dont work buddy. heres the vb source code

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

    Option Explicit

    Dim UserName As String
    Dim OldPassword As String
    Dim NewPassword As String
    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset

    Private Sub cmdCancel_Click()
    frmChangePassword.Hide
    End Sub

    Private Sub cmdOK_Click()

    UserName = txtUserName.Text
    OldPassword = txtOldPassword.Text
    NewPassword = txtNewPassword.Text

    End Sub

    Private Sub Form_Load()
    txtUserName.Text = ""
    txtOldPassword.Text = ""
    txtNewPassword.Text = ""

    Set cn = New ADODB.Connection
    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ManorOakHotel.mdb;Persist Security Info=False"
    cn.Open

    Set rs = New ADODB.Recordset
    rs.Open "SELECT * FROM StaffLogin", cn, adOpenDynamic, adLockOptimistic

    End Sub

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

    Database name is "ManorOakHotel.mdb"
    Table name is StaffLogin
    the name of the two fields are StaffUserName and StaffPassword

  4. #4
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089
    VB Code:
    1. Option Explicit
    2.  
    3. Dim UserName As String
    4. Dim OldPassword As String
    5. Dim NewPassword As String
    6. Dim cn As ADODB.Connection
    7. Dim rs As ADODB.Recordset
    8.  
    9. Private Sub cmdCancel_Click()
    10.         '  frmChangePassword.Hide
    11.            [b]unload Me[/b]
    12. End Sub
    13.  
    14. Private Sub cmdOK_Click()
    15.  
    16.         UserName = txtUserName.Text
    17.        OldPassword = txtOldPassword.Text
    18.        NewPassword = txtNewPassword.Text
    19. [b]
    20. If Rs.State = adStateOpen Then Rs.Close
    21.           Rs.CursorLocation = adUseServer
    22.             Rs.CursorType = adOpenKeyset
    23.             rs.LockType = adLockOptimistic
    24.             Rs.Open "select * from StaffLogin where StaffUserName like '' & txtUserName & " '",cn
    25.             If Not Rs.EOF Then
    26.                  'Username exists check for password
    27.                  If Rs("StaffPassword") = OldPassword Then
    28.                      'Old password entered correctly
    29.                      'Chnage the password
    30.                      Rs("StaffPassword") = NewPassword
    31.                      Rs.Update
    32.                      MsgBox "Password updated successfully"
    33.                  Else
    34.                       'Wrong password entered
    35.                       'inform user
    36.                       MsgBox "Invalid Password"
    37.                  End If
    38.             Else
    39.                 'Username does not exists
    40.                 ' inform the user
    41.                 MsgBox "Username not found"
    42.             End If
    43. [/b]
    44.  
    45. End Sub
    46.  
    47. Private Sub Form_Load()
    48.           txtUserName.Text = ""
    49.           txtOldPassword.Text = ""
    50.          txtNewPassword.Text = ""
    51.  
    52.         Set cn = New ADODB.Connection
    53.        cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ManorOakHotel.mdb;Persist Security Info=False"
    54.          cn.Open
    55.  
    56.       Set rs = New ADODB.Recordset
    57.      '  rs.Open "SELECT * FROM StaffLogin", cn, adOpenDynamic, adLockOptimistic
    58.  
    59. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width