|
-
Feb 15th, 2004, 02:18 PM
#1
Thread Starter
New Member
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
-
Feb 16th, 2004, 12:30 AM
#2
Member
Use the Following code
It might work or else let me know it and post the codeusing VBcode tag
VB Code:
rs.open "Select * from Table where userName='" & txtuser & "' and password='" & txtPass & "'",connection,adopendynamic,adlockoptimistic
if not rs.eof then
con.execute "Update table set password='" & txtpassword & "' where username='" & txtuser& "'"
endif
rs.close
Knowledge is divine and he who pass the knowledge is ..........
-
Feb 16th, 2004, 06:36 PM
#3
Thread Starter
New Member
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
-
Feb 17th, 2004, 04:39 AM
#4
PowerPoster
VB 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
[b]unload Me[/b]
End Sub
Private Sub cmdOK_Click()
UserName = txtUserName.Text
OldPassword = txtOldPassword.Text
NewPassword = txtNewPassword.Text
[b]
If Rs.State = adStateOpen Then Rs.Close
Rs.CursorLocation = adUseServer
Rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
Rs.Open "select * from StaffLogin where StaffUserName like '' & txtUserName & " '",cn
If Not Rs.EOF Then
'Username exists check for password
If Rs("StaffPassword") = OldPassword Then
'Old password entered correctly
'Chnage the password
Rs("StaffPassword") = NewPassword
Rs.Update
MsgBox "Password updated successfully"
Else
'Wrong password entered
'inform user
MsgBox "Invalid Password"
End If
Else
'Username does not exists
' inform the user
MsgBox "Username not found"
End If
[/b]
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|