473,323 Members | 1,537 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

change password control for asp.net based on SQl server

parshupooja
159 100+
Hi

I have created a login page which has user name n password. After entering values it authenticate from SQL Server and if it is correct, it forwards to designated page otherwise shows invalid login message. i have 5000 users in my system, so i opted this way. Now i want ot create a button on login page which shows change password. I want to replace my old password field value with new password field. I don't want to create another column and don't want to use asp web administration tool

any help will be appreciated

thank you
Jul 23 '07 #1
7 5369
Have you looked at the at the login controls provided in ASP.Net 2.0? They are simple to use. A control that may be useful to you could be the Password Recovery Web Control.

Christopher Pond
Innovative Website Development
Jul 24 '07 #2
Check out the membership APIs as well. All this functionality is build into ASP.net 2.0

Check out this Article

Christopher Pond
Innovative Website Development
Jul 24 '07 #3
parshupooja
159 100+
Hi,

thank You for response, but i do not want to use SQLmembershipprovider. I want to create simple change password tool which asks for current password and new password and based on that it should replace old password with new password in database. I have only 3 columns in database - user, password and email.

thank You
Jul 24 '07 #4
I would add a form with 3 text boxes as you'll see in many web sites.,

Enter Old Password ()
Enter New Password()
Confirm New Password()

Then in SQL(psedo Code) Update Table set Password= NewPassword where Password = OldPassword And Email = Email.

Does that help?
Jul 24 '07 #5
parshupooja
159 100+
thank you, it did work out but when i am trying to put validators on textboxes, it doesn't work
Jul 25 '07 #6
Plater
7,872 Expert 4TB
thank you, it did work out but when i am trying to put validators on textboxes, it doesn't work
What isn't working on the validators?
Jul 25 '07 #7
parshupooja
159 100+
Its working now, mistakenly I used Comparevalidator on both textboxes(New Password and Confirm New Password), it should be on one only.

Expand|Select|Wrap|Line Numbers
  1. <table style="text-align:right; width:auto;">
  2.         <tr><asp:ValidationSummary ID="ValSumm" runat="server" /><br /><asp:CompareValidator ID="ComValCNP" runat="server" ControlToCompare="NewPassword" ControlToValidate="ConfirmNewPassword">Password Should Match</asp:CompareValidator></tr><tr>
  3.             <td>
  4.                 <asp:Label ID="Label1" runat="server" Text="Current Password"></asp:Label></td>
  5.             <td>
  6.                 <asp:TextBox ID="CurrentPassword" runat="server" TextMode="Password" />
  7.                 <asp:RequiredFieldValidator ID="ReqFVCP" runat="server" ControlToValidate="CurrentPassword"
  8.                     ErrorMessage="Please Enter Current Password">*</asp:RequiredFieldValidator></td>
  9.         </tr>
  10.         <tr>
  11.             <td>
  12.                 <asp:Label ID="Label2" runat="server" Text="New Password"></asp:Label></td>
  13.             <td>
  14.     <asp:TextBox ID="NewPassword" runat="server" TextMode="Password"></asp:TextBox> <asp:RequiredFieldValidator ID="ReqFVNP" runat="server" ErrorMessage="Please Enter New Password" ControlToValidate="NewPassword">*</asp:RequiredFieldValidator>
  15.     </td>
  16.         </tr>
  17.         <tr>
  18.             <td>
  19.                 <asp:Label ID="Label3" runat="server" Text="Confirm New Password"></asp:Label></td>
  20.             <td>
  21.     <asp:TextBox ID="ConfirmNewPassword" runat="server" TextMode="Password"></asp:TextBox><asp:RequiredFieldValidator ID="ReqFVCNP" runat="server" ErrorMessage="Please Confirm New Password" ControlToValidate="ConfirmNewPassword">*</asp:RequiredFieldValidator>
  22.  
  23.     </td>
  24.         </tr>
  25.         <tr>
  26.             <td>
  27.     <asp:Button ID="Button1" runat="server"  Text="Save" OnClick="Button1_Click" /></td>
  28.    <td> <asp:Button ID="refresh" runat="server"  Text="Refresh" OnClick="refresh_Click" /></td>        
  29.         </tr>
  30.     </table>
  31.  
code behind
Expand|Select|Wrap|Line Numbers
  1. protected void Button1_Click(object sender, EventArgs e)
  2.    {
  3.  
  4.        string oldPassword = CurrentPassword.Text;
  5.         string newPassword = NewPassword.Text;
  6.         bool result = ChangeUserPassword(oldPassword, newPassword);
  7.    }
  8.    private bool ChangeUserPassword(string oldPassword, string newPassword)
  9.    {
  10.  
  11.         string query = "ChangePassword";
  12.         //string query = @"Update Users set Password = @NewPassword where Password = @OldPassword";
  13.         string connectionString = (string)ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
  14.         SqlConnection myConnection = new SqlConnection(connectionString);
  15.         SqlCommand myCommand = new SqlCommand(query, myConnection);
  16.         myCommand.CommandType = CommandType.StoredProcedure;
  17.         myCommand.Parameters.AddWithValue("@NewPassword", newPassword);
  18.         myCommand.Parameters.AddWithValue("@OldPassword", oldPassword);
  19.  
  20.         myConnection.Open();
  21.         string userId = (string)myCommand.ExecuteScalar();
  22.  
  23.         //string userId = (string)  myCommand.ExecuteScalar();
  24.         myConnection.Close();
  25.  
  26.         if (userId != null && userId.Length > 0)
  27.             return true;
  28.         else return false;
  29.     }
  30.  
Jul 25 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: william | last post by:
Hi, I have a dropdownlist control and a few textbox on my web form. How can I update those textbox content when user select item from dropdownlist control? I really want to do this on client...
0
by: Pavan | last post by:
Hi All, I am using Password Recovery control in order to reset my hashed passwords in ASP .Net 2.0 Beta 2. The system generated password is too difficult to remember, so i am giving Change...
6
by: a_hartmann_andersen | last post by:
Hi Guys Here is the problem: Im bored changing the local administrator password for a set of servers in a domain. So I though that I would write myself a little tool in C# to do that. I found...
1
by: John | last post by:
Hi I am using the Change Password control which works fine and changes the password. I have two problems; 1. After password has been changed, pressing continue goes no where. How can I tell...
3
by: Xnet | last post by:
I need to change password of a local user of a W2003, without Active Directory. I need to do it from an application created with VB2005. Thanks!
0
by: Ron | last post by:
Hi, I need to turn off my menu control when a user is in the process of changing there password. I know this can be done because the Login control automatically prevents the rendering of the...
1
by: roshina | last post by:
Hi Iam facing a problem in my project, developing a web site for online shopping in ASP on windows XP using IIS server. All the validations are ok but the new password is not upadated in the data...
2
by: =?Utf-8?B?V2FubmFiZQ==?= | last post by:
I added a change password control to my application and when I run the page that has it, I get an error: Generating user instances in SQL Server is disabled. Use sp_configure 'user instances...
3
by: =?Utf-8?B?QXhlbCBEYWhtZW4=?= | last post by:
Hi, we've got a strange problem here: We've created an ASP.NET 2.0 web application using Membership.ValidateUser() to manually authenticate users with our website. The problem is: If the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.