Category Archives: ChangePassword

ChangePassword

[RESOLVED]javascript should work after Regular Expression Validatior

Hi all,

        I have a form named ChangePassword.aspx. Here I am having 3 text boxes, 1st one is for old password, 2nd is for new password and the 3rd one is for confirm password.

       

 <tr>
            <td align="left" class="nbdcontent" style="width: 143px; height: 19px">
                Enter old password</td>
            <td align="center" class="nbdcontent" style="width: 10px; height: 19px">
                :</td>
            <td align="left" style="width: 100px; height: 19px">
                <asp:TextBox ID="txtOldpass" runat="server" CssClass="mytextbox" TextMode="Password"></asp:TextBox>
                <asp:RequiredFieldValidator ID="rfvOldpass" runat="server" ControlToValidate="txtOldpass"
                    ErrorMessage="Please enter Old Password !">*</asp:RequiredFieldValidator></td>
        </tr>
        <tr>
            <td align="right" class="nbdcontent" style="height: 19px" colspan="3">
                         <asp:RegularExpressionValidator ID="Regex2" runat="server" ControlToValidate="txtNewPass"
    ValidationExpression="[a-z]+"
    ErrorMessage="Minimum 8 characters atleast 1 Alphabet, 1 Number and 1 Special Character" 
                             ForeColor="Red" >*</asp:RegularExpressionValidator>
            </td>
        </tr>
        <tr>
            <td align="left" class="nbdcontent" style="width: 143px; height: 19px">
                Enter new password</td>
            <td align="center" class="nbdcontent" style="width: 10px; height: 19px">
                :</td>
            <td align="left" style="width: 100px; height: 19px">
                <asp:TextBox ID="txtNewPass" runat="server" CssClass="mytextbox" 
                    TextMode="Password"></asp:TextBox>
                <asp:RequiredFieldValidator ID="rfvNpass" runat="server" ControlToValidate="txtNewPass"
                    ErrorMessage="Please enter New Password !">*</asp:RequiredFieldValidator></td>
        </tr>
        <tr>
            <td align="right" class="nbdcontent" style="height: 19px" colspan="3">
                         <asp:RegularExpressionValidator ID="Regex3" runat="server" ControlToValidate="txtNCpass"
    ValidationExpression="^(?=.*[A-Za-z])(?=.*d)(?=.*[$@$!%*#?&])[A-Za-zd$@$!%*#?&]{8,}$"
    ErrorMessage="Minimum 8 characters atleast 1 Alphabet, 1 Number and 1 Special Character" 
                             ForeColor="Red" >*</asp:RegularExpressionValidator>
            </td>
        </tr>
        <tr>
            <td align="left" class="nbdcontent" style="width: 143px; height: 19px">
                Confirm password</td>
            <td align="center" class="nbdcontent" style="width: 10px; height: 19px">
                :</td>
            <td align="left" style="width: 100px; height: 19px">
                <asp:TextBox ID="txtNCpass" runat="server" CssClass="mytextbox" 
                    TextMode="Password"></asp:TextBox>
                <asp:RequiredFieldValidator ID="rfvNCP" runat="server" ControlToValidate="txtNCpass"
                    ErrorMessage="Please enter confirm New  Password">*</asp:RequiredFieldValidator>
                <asp:CompareValidator ID="cvNPass" runat="server" ControlToCompare="txtNewPass" ControlToValidate="txtNCpass"
                    ErrorMessage="Password did not match !">*</asp:CompareValidator></td>
        </tr>
        <tr>
            <td align="left" class="nbdcontent" style="width: 143px; height: 19px">
            </td>
            <td align="center" class="nbdcontent" style="width: 10px; height: 19px">
            </td>
            <td align="left" style="width: 100px; height: 19px">
            </td>
        </tr>
        <tr>
            <td align="left" class="nbdcontent" style="width: 143px; height: 19px">
            </td>
            <td align="center" class="nbdcontent" style="width: 10px; height: 19px">
            </td>
            <td align="left" style="width: 100px; height: 19px">
                <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Update" />

Here I I have used RegularExpressionValidator  for password complexity. I am also encrypting the password word on client side.

below is my code for encrypting password.

<script type="text/javascript" src="../js/md5.js">  </script>
    <script type="text/javascript">

     function ChangePwd(salt) {

         var control = "<%=txtOldpass.ClientID %>";
         if (document.getElementById(control).value != "") {

             document.getElementById(control).value =
                    hex_md5(document.getElementById(control).value);

             document.getElementById(control).value =
                    hex_md5(document.getElementById(control).value + salt);
         }

         var control2 = "<%=txtNCpass.ClientID %>";
         if (document.getElementById(control2).value != "") {
         

             document.getElementById(control2).value =
                    hex_md5(document.getElementById(control2).value);
         }

         var control3 = "<%=txtNewPass.ClientID %>";
         if (document.getElementById(control3).value != "") {
           
             document.getElementById(control3).value =
                    hex_md5(document.getElementById(control3).value);
         }
     }
    </script>

and on page load

I am adding an attribute to the button

Button1.Attributes.Add("onclick", "return ChangePwd('" + salt.ToString() + "'); ToggleButton();");

The problem is :- as I click the button to change the password, it encrypt the entered string in the textboxes. As the password is encrypted now doesn’t meet the password complexity.

I want that, first it run the regular expression validator then it should encrypt the password.

Any Idea how to achieve this.

Hi demoninside,

Thanks for your post.

As for your problem, in fact, RegularExpressionValidator control validates the value of “txtNCpass” two times. The first time, when “txtNCpass” TextBox lose focus, RegularExpressionValidator control validates the value of “txtNCpass”. The second time, if
you click Button1, the page will refesh and RegularExpressionValidator control validates the value again. In this situation, encrypted password will not meet the password complexity.

To solve this problem, we could set IsValid property to true from behind code as below.

protected void Button1_Click(object sender, EventArgs e)
{
    Regex3.IsValid = true;
} 

Hope it will be helpful to you.

Best Regards,

Fei Han

[RESOLVED]IMAGE BUTTON

Hey there!

Do you guys know to make an image become hyperlink to another aspx page in ASP.net ???

what i HAVE is 

<asp:Image ID="changepwdticon" src="images/changewdticon.png" onClick="~/ChangePassword.aspx" runat="server" /></td>

it does not work at all! please help me  Cry

try this

<asp:HyperLink runat=server NAvigateUrl=".."><asp:Image></asp:Image></asp:HyperLink>

FormAuthentication [AjaxToolkit exlusucion issue]

I have a ASP.NET website with Forms authenction and deny annonymous user. Unforunately I transfer the users to a changepassword page if their password has expired right from the global.asax event void Application_PostAuthenticateRequest(object sender, EventArgs
e) . The changePassword page uses the ajaxtoolkit.and is throwing exception of not finding it. How can I pass an exclusion rule to allow the toolkit to be loaded for annonymous user? I know how to add exclusion for directories and specific pages but how to
do for the toolkit

Hi,

Make sure you install the correct version of the AjaxControlToolkit:

Version 3.0.20229 2008-02-29 release of the AJAX Control Toolkit targets the official release of .NET Framework 3.5 and Visual Studio 2008.

Version 1.0.20229 You can also download the Toolkit for .NET Framework 2.0, ASP.NET AJAX 1.0 and Visual Studio 2005.

Version 3.0.40412

April 12, 2010 release of the AJAX Control Toolkit for ASP.NET 3.5 Service Pack 1 and Visual Studio 2008 SP1.

Version 4.1.51116.0

Nov 16 2011 release of the AJAX Control Toolkit for ASP.NET 4.0 and Visual Studio 2010

Version 4.1.60919

September 2012 release of the AJAX Control Toolkit for ASP.NET 4.5 and Visual Studio 2012

Then you could add the Ajax Control Toolkit to the VS Toolbox step by step at:http://www.asp.net/ajaxlibrary/act.ashx

My question is how can I allow access to the toolkit for a locked down site(which doesn’t allow annonymous access)

Membership user in 2010

I’m tryint to convert some existing code to the new framework and according to microsoft the membership stuff has been pushed to System.Web.ApplicationServices so I added the reference and imported the System.Web.Security namespace but MembershipUser continues
to error…what am I doing wrong?

 

daCodez

and according to microsoft the membership stuff has been pushed to System.Web.ApplicationServices

The old membership classes are still in the same assembly/namspace.Nothing moved.The

mentioned namespace
is a new one that allows you to expose the Membership and other security providers as wcf services to allow external applications to use your membership system.

So i think you should not change your code, if you are getting an exception, you should post it here.

I’ve been through all the .net 4 assemblies and i cannot find a system.web.security assembly when i go to add a reference.  I’ve even reinstalled the .net framework twice. 

Edit: there is no "System.web.Security" assembly.It’s a namcespace in "System.Web" assembly.

System.Web is already referenced in my project.  The error i’m getting is:

 

Error 17 Type ‘System.Web.Security.MembershipUser’ in assembly ‘System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ has been forwarded to assembly ‘System.Web.ApplicationServices’. Either a reference to ‘System.Web.ApplicationServices’
is missing from your project or the type ‘System.Web.Security.MembershipUser’ is missing from assembly ‘System.Web.ApplicationServices’. F:Documents and SettingsCodezMy DocumentsVisual Studio 2010WebSitesDataAccessFrameworkTestSiteApp_CodeBasePage.vb 495 24 F:…DataAccessFrameworkTestSite

 

and I’ve added a reference to that assembly alread.

 

Try to remove the reference to "System.Web.ApplicationServices" assembly through project references(if you are workign with web application) or assemblies section in  web.config file(if you are working with website project model)

I’ve removed the reference and I am still getting the same error. 

Do you have <assemblyBinding> section in web.config file ? it should be under <runtime> section.If so, please post it  here.

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
			<dependentAssembly>
				<assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
				<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
			</dependentAssembly>
			<dependentAssembly>
				<assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
				<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
			</dependentAssembly>
		</assemblyBinding>

 

Hmm, weird,weird weird !

What is the type of the project you are currently using ? is it web application(have project icon)? or  website ? and what is the langauge ?vb or c#? And are you getting that error in a specific page ? or during compliation ?

It’s a website in VB and it is in my base page class.  I’m getting the error in design mode so it see the squiggly line. 

 

Protected Sub LogActivity(ByVal action As String)
        If Request.IsAuthenticated Then
            Dim usr As MembershipUser = Membership.GetUser
            If usr Is Nothing Then
                DisplayAlert("Unknown User!")
                Exit Sub
            End If


            'Get user's UserId value
            Dim UserId As Guid = CType(usr.ProviderUserKey, Guid)




            Dim connectionString As String = MembershipHelper.GetMembershipConnectionString()
            Using con As New SqlConnection(connectionString)
                con.Open()
                Dim cmd As New SqlCommand("WebCoreDB_Activity_UpdateCurrentActivity", con)
                cmd.CommandType = Data.CommandType.StoredProcedure
                cmd.Parameters.AddWithValue("@UserId", UserId)
                cmd.Parameters.AddWithValue("@Action", action)
                cmd.Parameters.AddWithValue("@CurrentTimeUtc", DateTime.UtcNow)
                cmd.ExecuteNonQuery()
                con.Close()
            End Using


        End If
    End Sub

Not sure that my code will help but here is one of the underlying functions in my base page.

I think you are correct ! All the membership related classes have been moved to a new assembly "System.Web.ApplicationServices".

I just checked the error you are getting and it seems that the solution is to make sure that you already have reference to System.Web.ApplicationServices.

The new assembly is registered in the framework config file and so it should be available to your website when it’s converted to .net 4.

For some reason, the error tells that your website doesn’t have reference to that assembly.So you will need to try adding explicitly in the web.config file of your site.

So the assemblies section should become like this:

<compilation debug="false" strict="false" explicit="true" targetFramework="4.0">
      <assemblies>
        <add  assembly="System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </assemblies>
</compilation>

If you still see that error, try this instead:

<compilation debug="false" strict="false" explicit="true" targetFramework="4.0">
      <assemblies>
        <remove assembly="System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <remove  assembly="System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add assembly="System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <add  assembly="System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </assemblies>
</compilation>

I am also using VWD 2010 Express and getting the same error on code that worked fine in VWD 2008 Express.  I added the four lines you mention above to my web.config file, but my code (below) still ends up with a squiggly blue line under the lines in red and
when I expand the error it says:

Protected Sub ChangePassword(ByVal Username As String, ByVal NewPassword As String)
        Dim member As MembershipUser = Membership.GetUser(Username)
        member.ChangePassword(member.ResetPassword, NewPassword)
        member.Comment = ""
        member.Email = ""
        Membership.UpdateUser(member)
    End Sub

The error says:

Reference required to assembly ‘System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′ containing the type ‘System.Web.Security.MembershipUser’. Add one to your project.

It even provides a hyperlink that says,

Add reference ‘System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′ to project ‘Grading’

ut when I click on it it does nothing.

YES! Thank you. I am getting this same exact error

It’s one of the breaking changes in ASP.NET 4,

Please take a look at
this link
for the workaround and let us know if it solved your problem.

Well with my situation I only get the "error" blue underlines in Visual Studio. When i run the site everything works fine. Its annoying (since i’m OCD) but its not stopping anything

I had this same issue i tried everything.  I then noticed the line that would fix it is this..

<compilation debug="true" strict="false" explicit="false" targetFramework="4.0">

I didnt have the targetFramework="4.0" framework part of it inplace. Once i added that the errors went away.

That link doesn’t work.

I have the same problem, and it’s driving me nuts.

Who had the bright idea of creating a namespace in one assembly that already existed in another?  

[RESOLVED]JQuery fails on validator in subfolder

This is a strange twist, and probably a simple coding problem.

In my master page I define jquery slide out tabs.  In the master page Head section I use ResolveUrl to ensure that the subfolders can see the code.  I am also using the Membership functionality which is all contained in an Account subfolder.  I’ll use the
ChangePassword page as an example of the problem I’m having.

When ChangePassword.aspx first loads, the slide out tabs are visible.  However, if I just click on the Submit button, the validation text appears, but the slide out tabs are no longer visible.

Here is one of the aspx page’s textboxes, for the old password (I’m using the ChangePasswordTemplate):

<asp:TextBox ID="CurrentPassword" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="CurrentPasswordRequired" runat="server" ControlToValidate="CurrentPassword"
                                                            CssClass="failureNotification" ErrorMessage="Password is required." ToolTip="Current Password is required."
                                                            ValidationGroup="ChangeUserPasswordValidationGroup">*</asp:RequiredFieldValidator>

Here is the Submit button markup.  The OnClick event just reloads the page using Response.Redirect, which works in that it preserves the slide out tabs, but of course you lose the validation text.

                                <asp:Button ID="ChangePasswordButton" runat="server" CommandName="ChangePassword" Text="Submit" 
                                            OnClick="ChangePasswordButton_Click" />

I’ve tried using javascript to capture the validation text and save it to a hidden field (removing the OnClick event), but that hidden field’s text is always getting reset to blank on partial postback.  I’ve also looked up jquery validation, but then I have
to write my own ChangePassword code, whereas I’d rather use the built-in CommandName functionality.  I’ve checked and indeed the master page code is not getting fired on the validator’s partial postback.  I’ve tried forcing it to fire using client side pageLoad,
but so far without success.

There must be a simple reason why the master page is not being reloaded when the ChangePassword page’s validator’s are being fired, or at least I hope so!

Thanks!

 

Of course, another option is to move all the Account subfolder pages up to the main folder, but that seems a bit draconian…