Oops... Shouldn't it be .net?
Main Topics
Browse All TopicsI have a SQL table that I have user names and passwords in. I want the user to be able to change their passwords. So I created a form that says: (I'm also using VB.NET as codebehind)
UserName: txtUserName
OldPassword: txtOldPass
NewPassword: txtNewpass
Change Button btnChange
So, How do I write the code to let the user change the password through the form?
THANKS!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
gcargile,
Here's my complete version about what you need :
changePassword.aspx
========================
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="changePassword
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>changePassword</tit
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScri
<meta name="vs_targetSchema" content="http://schemas.mi
</HEAD>
<body MS_POSITIONING="GridLayout
<form id="Form1" method="post" runat="server">
<asp:Label id="lblUser" style="Z-INDEX: 101; LEFT: 24px; POSITION: absolute; TOP: 56px" runat="server">UserName</a
<asp:TextBox id="txtUserName" style="Z-INDEX: 102; LEFT: 144px; POSITION: absolute; TOP: 56px"
runat="server" Width="208px"></asp:TextBo
<asp:Label id="lblOldPassword" style="Z-INDEX: 103; LEFT: 24px; POSITION: absolute; TOP: 96px"
runat="server">Old Password</asp:Label>
<asp:TextBox id="txtOldPassword" style="Z-INDEX: 104; LEFT: 144px; POSITION: absolute; TOP: 96px"
runat="server" Width="208px"></asp:TextBo
<asp:TextBox id="txtNewPassword" style="Z-INDEX: 105; LEFT: 144px; POSITION: absolute; TOP: 136px"
runat="server" Width="208px"></asp:TextBo
<asp:Label id="lblNewPassword" style="Z-INDEX: 106; LEFT: 24px; POSITION: absolute; TOP: 136px"
runat="server">New Password</asp:Label>
<asp:RequiredFieldValidato
runat="server" ErrorMessage="Please fill in userName" Font-Bold="True" ControlToValidate="txtUser
<asp:RequiredFieldValidato
runat="server" ErrorMessage="Please fill in old password" Font-Bold="True" ControlToValidate="txtOldP
<asp:RequiredFieldValidato
runat="server" ErrorMessage="Please fill in new password" Font-Bold="True" ControlToValidate="txtNewP
<asp:Button id="btnChange" style="Z-INDEX: 110; LEFT: 144px; POSITION: absolute; TOP: 192px"
runat="server" Text="Change Password"></asp:Button>
<asp:Label id="lblStatus" style="Z-INDEX: 111; LEFT: 144px; POSITION: absolute; TOP: 248px"
runat="server" Font-Bold="True" ForeColor="Red"></asp:Labe
</form>
</body>
</HTML>
changePassword.aspx.vb
====================
Imports System.Data
Imports System.Data.SqlClient
Public Class changePassword
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.Debugg
End Sub
Protected WithEvents lblUser As System.Web.UI.WebControls.
Protected WithEvents txtUserName As System.Web.UI.WebControls.
Protected WithEvents lblOldPassword As System.Web.UI.WebControls.
Protected WithEvents txtOldPassword As System.Web.UI.WebControls.
Protected WithEvents txtNewPassword As System.Web.UI.WebControls.
Protected WithEvents lblNewPassword As System.Web.UI.WebControls.
Protected WithEvents RequiredFieldValidator1 As System.Web.UI.WebControls.
Protected WithEvents RequiredFieldValidator2 As System.Web.UI.WebControls.
Protected WithEvents RequiredFieldValidator3 As System.Web.UI.WebControls.
Protected WithEvents btnChange As System.Web.UI.WebControls.
Protected WithEvents lblStatus As System.Web.UI.WebControls.
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclara
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub btnChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChange.Click
If Page.IsValid Then
Dim conData As SqlConnection = New SqlConnection("server=loca
Dim strSQL As String
Dim objDataAdapter As SqlDataAdapter
Dim objCB As SqlCommandBuilder
Dim objDataSet As DataSet = New DataSet
'userName as primary key
'table tblUser - userName,password
strSQL = "select userName,password from tblUser where userName=@userName"
objDataAdapter = New SqlDataAdapter(strSQL, conData)
objCB = New SqlCommandBuilder(objDataA
objDataAdapter.SelectComma
objDataAdapter.MissingSche
objDataAdapter.SelectComma
objCB.RefreshSchema()
objDataAdapter.Fill(objDat
'check wheter exist this logged in user or not
If objDataSet.Tables("tblUser
'check existing old password - must match, not ignore case sensitive
If String.Compare(Trim(objDat
objDataSet.Tables("tblUser
objDataAdapter.Update(objD
lblStatus.Text = "Success change the old password!!!"
Else
lblStatus.Text = "Please insert valid old password!!"
End If
Else
lblStatus.Text = "Please insert an valid userName!!!"
End If
objDataSet.Tables("tblUser
End If
End Sub
End Class
-I'd include all the details explanations had include inside the code.
Regards
x_com
Great... Thanks x_com.... I get this error though:
Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationExc
Source Error:
Line 59: If String.Compare(Trim(objDat
Line 60: objDataSet.Tables("Credent
Line 61: objDataAdapter.Update(objD
Line 62: lblStatus.Text = "Success change the old password!!!"
Line 63: Else
x_com: Only if you feel like, but will you explain these lines...
objDataAdapter.SelectComma
'Why do I need the sql command in selectcommand.commandtext ?
objDataAdapter.MissingSche
'What is MissingSchemaAction?
objDataAdapter.SelectComma
'What am I adding exactly?
objCB.RefreshSchema()
This worked very nicely by the way!
gcargile ,
Here my explanations:
objDataAdapter.SelectComma
-Use to select old password - before any changes
objDataAdapter.MissingSche
-Adds the necessary columns and primary key information to complete the schema. For more information about how primary key information is added
objDataAdapter.SelectComma
-select field from DB based on criteria (here i'm using userName as a search keyword).This keyword will replace the value for @userName inside SQL statement as you see in my code.
eg:
strSQL = "select userName,password from tblUser where userName=@userName"
objCB.RefreshSchema()
-you need to use it for any SELECT statement associated with the SqlCommandBuilder changes.
Hope that clear for you.
Regards
x_com
Business Accounts
Answer for Membership
by: ho_alanPosted on 2003-12-08 at 19:17:03ID: 9901539
assume the user has already login, here is the basic idea
ldPass")
ss")
hope can inspire u :-)
change password:
please enter the old password
<form method=post action=updatePwd1.asp>
<input type=password name=txtOldPass>
<input type=submit value=submit>
</form>
updatePwd1.asp
<%
oldPass=request.form("txtO
'sql stuff, open connection
'if old password matches, ask user to enter new password
%>
<form method=post action=updatePwd2.asp>
<input type=password name=newPass>
<input type=password name=confirmNewPass>
<input type=submit value=submit>
</form>
<%'end if%>
updatePwd2.asp
<%
newPass = request.form("newPass")
confirmNewPass = request.form("confirmNewPa
if not newPass = confirmNewPass then
'go back
else
'open DB connection, assume lgName stored the logged in name for user
'strSQL = "update urTable set Password="&newPass &"where logname="&lgName
end if
%>