Why does textmode=password causes issue in asp.net? - c#

I am facing a very peculiar issue.
I have set textmode of an asp.net textbox to Password but it causes a problem i.e. it picks other passwords from cookies even it has nothing to do with my page.
And setting it to password also affects my another textbox with is set to SingleLine mode but when I remove Password textmode then it works correctly.
<asp:TextBox ID="txtPassword1" TextMode="Password" runat="server" CssClass="form-control"></asp:TextBox>
<asp:TextBox ID="txtUserLogin1" TextMode="SingleLine" runat="server" CssClass="form-control"></asp:TextBox>

Regarding this
it picks other passwords from cookies even it has nothing to do with my page.
I think it a browser functionality which automatically populates saved password for you. So when you have type as "password", it shows you some password. Try to clear saved password and then you will see blank textbox.
I am not sure about the second issue.

I added dummy text box
<asp:TextBox ID="dummy" runat="server" style="display:none"></asp:TextBox>
under the textbox which was showing prefilled data from cache. It solved my problem.

Try to use type="Password" instead of TextMode="Password"

Related

Autocomplete HTML Attribute Not Disabled for Password Field

Security scan of our server says
Autocomplete HTML Attribute Not Disabled for Password Field.
Fix: Correctly set the "autocomplete" attribute to "off"
Reasoning: AppScan has found that a password field does not enforce
the disabling of the autocomplete feature
After seeing this report I have set autocomplete=off and AutoCompleteType="Disabled" for username and password textboxes. But it makes no change. Browser asks for Remember password and if click yes, autocomplete feature is enabled there. How can I resolve this? Or is there any mechanism to force stop the browser for asking remember password?
<asp:TextBox ID="tb_loginid" autocomplete="off" AutoCompleteType="Disabled" runat="server" ForeColor="#5D7B9D"></asp:TextBox>
<input type="password" style="display:none;"/>
<asp:TextBox ID="tb_password" autocomplete="off" AutoCompleteType="Disabled" runat="server" ForeColor="#5D7B9D" TextMode="Password" >*</asp:TextBox>
You may try with the below attribute on the form tag(if this is inside a form-which it should be in all fairness)
<form method="post" action="YourAction" id="loginForm" autocomplete="off">

Automate ASP.NET login form by automatically populating credentials

I have an existing Login.aspx page that works when a user manually populates their login credentials and submits them.
I would like to create another version of this form for 'TRIAL' purposes that automatically populates the username and password textbox fields with values. I would like to make these textbox controls hidden. So essentially user just hits login button, it uses the automatically populated values, and logs the user in.
How can I convert existing code to do this?
Here is the code with the two textbox controls for username and password:
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName"
Text="Username">
</asp:Label>
<asp:TextBox ID="UserName" runat="server"></asp:TextBox>
<asp:CustomValidator ID="UserNameRequired" ValidateEmptyText="True"
OnServerValidate="ValidateUserName" ClientValidationFunction=""
runat="server" ControlToValidate="UserName"
ErrorMessage="<%$ resources: UserNameRequired %>"
ToolTip="<%$ resources: UserNameRequired %>" ValidationGroup="sLogin"
Text="<%$ resources: asterisk %>">
</asp:CustomValidator>
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password"
Text="<%$ resources: Password %>" Style="margin-top: 5px;"></asp:Label>
<asp:TextBox ID="Password" runat="server" CssClass="editCtl"
TextMode="Password" AutoComplete="off"></asp:TextBox>
I realize I can simply add the values directly into the page like this:
<asp:TextBox ID="UserName" runat="server" Text="user1" style="display:none;"></asp:TextBox>
<asp:TextBox ID="Password" runat="server" CssClass="editCtl" AutoComplete="off" Text="password1" style="display:none;"></asp:TextBox>
However, I guess the REAL question would then be how do I call these values in a more secure way?
From your OP I am making the following assumptions: You have two login pages, one for the normal users and one for the trial users. Both of these .ASPX pages are sharing the same code behind page in order to share the logic. This results in the trial login page needing to supply the username and password without the user entering it, and you don’t want those easily visible to the user.
You can use a second submit button for the trial login. On the normal page the trial submit button would be hidden and on the trial page the username, password and normal submit is hidden.
Refactor the code behind page so the login logic is in a separate method. For the normal login page get the username and password from the UI controls and call the method. In the trial button click use hard coded values, or better yet configured values, and call the method.
What about store the data, encoded into a cookie, and fill the input value if this cookie exist?
C#
Response.Cookies["userName"].Value = "patrick";
Response.Cookies["userName"].Expires = DateTime.Now.AddDays(1);
VB
Response.Cookies("userName").Value = "patrick"
Response.Cookies("userName").Expires = DateTime.Now.AddDays(1)

ASP.NET Javascript runtime error

I have just started a new ASP.NET web application and I am totally new to everything and after moving a few things round I have been getting this error and I don't understand what it means.
It happens when I go to enter anything in the Password box.
Could someone please help me out on this issue.
EDIT:
<li>
<asp:Label runat="server" AssociatedControlID="Password">Password</asp:Label>
<asp:TextBox runat="server" ID="Password" TextMode="Password" onkeypress="capLock(event)" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="Password" CssClass="field-validation-error" ErrorMessage="The password field is required." />
</li>
Try to do that inside
window.onload = function(){
// code goes here
}
I think you are trying to access DOM even before it is being created.
the document.getElementById('divMayus') is undefined
document.getElementById("divMayus") is returning null or undefined.
You should look at the rendered html and find the div that you are trying to reference to make sure the id is the same as you are trying to reach. Asp.net alters the ids of server controls depending on their containers. So if you moved stuff around, the id may have also been changed.

Required Field Validator for login page in asp.net

I'm working on the login in one of my asp.net project.
I have completed the login page but facing problem when I have included asp.net validation.
I have inserted required field validator for the username and password textbox in my login page,I have link for new user registration and also forget password.
My problem is, eventhough I want to click new user or forget password link, required field validator for textbox and username shows error message.
You need to use ValidationGroup Property to fix this.
ex:
<asp:textbox id="tb1" runat=Server />
<asp:requiredfieldvalidator id="ReqField1" controltovalidate="tb1"
validationgroup="valGroup1" errormessage="Required" runat=Server />
<asp:ImageButton id="Button2" causesvalidation=true
validationgroup="valGroup2" ImageUrl="img.gif" runat=Server />
Or Else
Assign CauseValidation="False" in New registration and Forget Password Button to fix
Add CausesValidation="false" to the links that should not trigger validation.
change the validation group of these two linkbuttons (forget password, New user linkbuttons) to be not the same of the login button control and I hope your problem will be solved :)..

Issue related to lost focus in Textbox when RequiredValidator is used

I have an asp.net Web Application, i have login screen in Application.
In userName and password field i have used required field validator as follows :
<td style="width: 160px">
<asp:TextBox ID="txtUserNm" runat="server" CssClass="txtSingleline txtBack-Color txtRequireBorder-Color required" Height="18px" Width="150px" TabIndex="1" MaxLength="50" onblur="ValidatorOnChange(event);showhide();"></asp:TextBox>
</td>
<td style="width: 140px">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Display="Dynamic"
Width="150px" SetFocusOnError="true" ErrorMessage="Please enter Username" ControlToValidate="txtUserNm" ValidationGroup="a"></asp:RequiredFieldValidator>
when i focus on UserName textbox and Press Tab , i am unable to loos the focus from the TextBox because of RequiredField Validator. it happens only in Chrome and IE9 . but working well in firefox.
what can be solution to loose the focus from the Textbox when using Requiredfield validator ???
Thanks
Simple... just remove the SetFocusOnError="true" or set it to false.
The only downside is you can only validate the form on form post back, not on the fly.
But, it's not even such a pain in the neck, since even if you remove this property, validation works fine in both normal web forms, and ajax update panels.
I assume that you should manually assign tabindex property to your controls in order to define loop by pressing tab.

Categories