Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hie,

This is the problem: I CAN'T get my browser to prompt me to save the password for the site I'm developing. (I'm talking about the bar that appears sometimes when you submit a form on Firefox, that says "Remember the password for yoursite.com? Yes / Not now / Never")



how can i get it ? my code is given below:

for login.aspx

C#
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="login.aspx.cs" Inherits="login" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title>Wereldschool - Leerlingvolgsysteem</title>
    <link href="style/login_style.css" rel="stylesheet" type="text/css" />
    <script type='text/javascript'>
        function clearTextBox1() {
            if (document.getElementById("txtPassword").value == '') {
                document.getElementById("txtPassword").value = 'wachtwoord';
                document.getElementById("txtPassword").type = "text";
            }
        }
        function clearTextBox(textBoxID) {
            if (document.getElementById(textBoxID).value == 'Gebruikersnaam') {
                document.getElementById(textBoxID).value = '';
                if (document.getElementById("txtPassword").value == '') {
                    document.getElementById("txtPassword").value = 'wachtwoord';
                    document.getElementById("txtPassword").type = "text";
                }
            }
            if (document.getElementById(textBoxID).value == 'wachtwoord') {

                document.getElementById(textBoxID).value = '';
                document.getElementById(textBoxID).type = "password";
                if (document.getElementById("txtUsername").value == '') {
                    document.getElementById("txtUsername").value = 'Gebruikersnaam';
                }
            }
        }  </script>
</head>
<body>
    <form id="form1"  runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" AsyncPostBackTimeout="20000">
    </asp:ScriptManager>
    <div class="contain">
        <div class="container">
            <div class="header">
                <div class="logo">
                    <img alt="logo" src="images/logos.png" />
                </div>
            </div>
        </div>
        <!--LOGIN START-->
        <div class="login">
            <div class="container">
                <div class="login-image">
                    <img alt="logo" src="images/logo_login.png" />
                </div>
                <div class="login-menu">
                    <p>
                        login</p>
                    <small>Voer uw gebruikersnaam en wachtwoord in:</small>
                    <div class="searchbar">
                        <asp:TextBox ID="txtUsername" Text="Gebruikersnaam" CssClass="textfield"  OnClick="clearTextBox(this.id)"
                            runat="server"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="rqdusername" runat="server" ControlToValidate="txtUsername"
                            ErrorMessage="*" Font-Size="Medium" ></asp:RequiredFieldValidator>
                        <br />
                        <asp:TextBox ID="txtPassword" Text="wachtwoord"  CssClass="textfield" OnFocus="clearTextBox(this.id)" OnBlur="clearTextBox1()" OnClick="clearTextBox(this.id)"
                            runat="server"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="rqdpwd" runat="server" ControlToValidate="txtPassword"
                            ErrorMessage="*" ></asp:RequiredFieldValidator>
                        <br />
                        <llvs:llvsButton ID="btnLogin"  runat="server" CssClass="btn" Text="Inloggen"  önClick="btnLogin_Click" />
                        <%--<input name="" type="button" value="LOGIN" class="btn" />--%>
                        <!--<input name="" type="button"  value="LOGIN" class="btn btn-blue"/>-->
                    </div>
                </div>
               
                <div>
                    <asp:Label ID="lblInvalidLogin" Font-Size="Small"   runat="server"></asp:Label>
                </div>
            </div>
        </div>
        <!--END LOGIN-->
    </div>
    <!--FOOTER START-->
    <div class="login_footer_bg">
        <div class="footer">
            <div class="login_footer_left">
                <div>
                    <a href="#">
                        <img src="images/wereldschool_logo.png" /></a><a href="#"><img src="images/logos_footer.png"
                            alt="" /></a>
                </div>
            </div>
            <div class="login_footer_right">
                <div>
                    <a href="#">Copyright Leerlingvolgsysteem. All Rights Reserved</a>
                    <br />
                    <a href="#">Powered by <span>Devrepublic</span></a>
                </div>
            </div>
        </div>
    </div>
    <!--END FOOTER-->
    </form>
</body>
</html>

and for login.aspx.cs file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using Wereldschool.LLVS.Bussineslayer;

public partial class login : System.Web.UI.Page
{
    public BussinesCollection bussinesCollection = new BussinesCollection(ConfigurationManager.ConnectionStrings["llvsDatabase"].ConnectionString);

    static string prevPage;
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            //Guid lcID = Guid.Parse("DBA09986-3D14-4DB5-90E8-B422FDFD981D");
            //Guid subID = Guid.Parse("C8133B20-8DB7-437B-A115-9ABC080D92CD");

            //m.bussinesCollection.BussinesMark.newSave(lcID, subID, "niet", new decimal(1));
            //m.bussinesCollection.BussinesMark.newSave(lcID, subID,null, new decimal(0),false);
            //m.bussinesCollection.BussinesMark.newSave(lcID, subID,null, new decimal(1),false);

            prevPage = "~/index.aspx";
            //if (Request.UrlReferrer != null)
            //{
            //    prevPage = Request.UrlReferrer.ToString();
            //    if (prevPage.Contains("logout.aspx"))
            //        prevPage = "index.aspx";
            //}
            //else
            //{
            //    prevPage = "index.aspx";
            //}
           
        }
    }

    protected void btnLogin_Click(object sender, EventArgs e)
    {

        if (txtUsername.Text.Length.Equals(0))
        {
            bool autoLoginSetting = bool.Parse((String)ConfigurationManager.AppSettings["AutoLogin"]);
            if (autoLoginSetting)
            {
                string username = (string)ConfigurationManager.AppSettings["Username"];
                string password = (string)ConfigurationManager.AppSettings["Password"];
                autoLogin(username, password);
            }
        }
        string melding = string.Empty;
        if (bussinesCollection.BussinesPerson.LoginUser(txtUsername.Text.Trim(), txtPassword.Text.Trim(), out melding))
        {
            Session["loggedInPersonID"] = bussinesCollection.BussinesPerson.LoggedInPerson.ID;
            Session["bbLocation"] = bussinesCollection.BussinesMessage.GetLocationId("Postvak In");

            //loginhistory tabel bijwerken
            try
            {
                string ipadres = Request.UserHostAddress ?? "Geen ip";
                string browserString = Request.UserAgent ?? "Geen query string";
                if (browserString.Count() > 250)
                    if (browserString.Count() > 0)
                        browserString = browserString.Substring(0, 249);

                Guid loginID;
                try
                {
                    loginID = bussinesCollection.BussinesPerson.setLoginHistory(bussinesCollection.BussinesPerson.LoggedInPerson.ID);
                    bussinesCollection.BussinesPerson.UpdateLoginHistory(loginID, browserString, ipadres);
                }
                catch (Exception ex)
                {

                }
            }
            catch (Exception ex)
            {
            }

            if (string.IsNullOrEmpty(prevPage))
            {
                Response.Redirect("~/index.aspx");
            }
            else
            {
                Response.Redirect(prevPage);
            }
        }
        else
        {
            lblInvalidLogin.Text = melding;
           // m.SetError(new Exception(melding));
            txtPassword.Text = string.Empty;

        }
    }

    private void autoLogin(string username, string password)
    {
        //Person p = personClass.loginUser("joostvs", "123456");
        //Person p = personClass.loginUser("docent1", "123456");
        //if (personClass.loginUser("joostvs", "123456", out p))
           string melding = string.Empty;
           if (bussinesCollection.BussinesPerson.LoginUser(username, password, out melding))
           {

               Session["loggedInPersonID"] = bussinesCollection.BussinesPerson.LoggedInPerson.ID;
               Session["bbLocation"] = bussinesCollection.BussinesMessage.GetLocationId("Postvak In");


               if (string.IsNullOrEmpty(prevPage))
               {
                   Response.Redirect("index.aspx");
               }
               else
               {
                   Response.Redirect(prevPage);
               }
           }
           else
           {
              lblInvalidLogin.Text = "Fout bij inloggen";
             //  m.SetError(new Exception("Fout bij inloggen"));
           }
    }
}






my all code is above..
so please suggest me the proper way.
i have 1 query that if we submit the form then is this possible to get this functionality.

Thanks in advance!
ketan
Posted
Updated 18-Jul-13 23:43pm
v2
Comments
Dholakiya Ankit 19-Jul-13 6:27am    
can you try cookies please............
ketan italiya 19-Jul-13 7:25am    
no,can you give me hint for that..?
Dholakiya Ankit 19-Jul-13 7:28am    
see i think in built control of asp.net remeber password have also this facility they are using same functionality see my solutions
Dholakiya Ankit 19-Jul-13 8:22am    
i have added links dude see solution3
ketan italiya 19-Jul-13 8:27am    
yehh..i see it sorry..

I guess That prompt is browsers inbuilt functionality. There might be some setting that is disabled at your end for same. When browser detect an <input> filed with type=password it prompts to save.

For firefox go to
Menu>Tools>Options

there is one check box "Remember Password for sites", Check it.
Now Click on "Exception" Button and removed all/Desire sites from there, for which you dont want to remember

To use feature of asp.net you can use cookies.
 
Share this answer
 
The "save password" part comes from the browser's password manager whenever it sees an <input type="password"/> that looks like it really is asking for a password. You can use the autocomplete attribute to suppress this in most browsers:
HTML
<input type="password" name="password" autocomplete="off" />


This won't validate but that usually doesn't matter.

The "remember me" part is completely separate from the browser's password manager. The "remember me" flag is the server's business and all it does is fiddle with the expiry date on the cookie that it sends back. The server will always send a cookie back (unless they're not using cookies for tracking sessions but that's rare and wouldn't need a "remember me" anyway) with something inside it to identify the client user.

If you check "remember me" then you're telling the server that you want a persistent session. To achieve this, the server will include an expiry date with the cookie and that expiry date will be some time in the future. When the date arrives, the browser will expire and delete the cookie; without the cookie, the server won't know who you are anymore and you'll have to login again.

If you don't check "remember me" then you'll get a session cookie. Session cookies don't have expiry dates on them so automatically expire when the browser exits. Session cookies are useful for shared machines.

Executive summary:

"Save password" is from the browser's password manager.
"Remember me" is about the login cookie's expiry time.

Sorry to be so long winded but there seems to be some confusion and a lack of clarity in the other answers.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900