Click here to Skip to main content
15,030,320 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
Hello,
I am using a MVC Razor View , now i would like to stop Auto complete option for Password Field. So far i am using autocomplete="off" but not working in crome.

Can anyone please help me on this ?
Posted
Updated 1-Dec-20 23:21pm

I found two promising approaches to that problem by googling for "disable autocomplete for password":

How to Turn Off Form Autocompletion - Web security | MDN[^]
html - Disabling Chrome Autofill - Stack Overflow[^]

If none of these work for you you might find other ways by looking at the other search results from Google.
   
Thanks everyone for your help. :) :)
But i got my solution that i would like to share with you.
Just create a fake Property like FakePassword & make this a style display None.

What will happen, browser will hit first @Html.PasswordFor , so it will not
affect the real one.

Thanks for your co-operation. :)
   
Take a look: How do you disable browser Autocomplete on web form field / input tag?

Quote:


Firefox 30 ignores autocomplete="off" for passwords, opting to prompt the user instead whether the password should be stored on the client. Note the following commentary from May 5, 2014:

The password manager always prompts if it wants to save a password. Passwords are not saved without permission from the user.
We are the third browser to implement this change, after IE and Chrome.

According to Mozilla developer documentation the form element attribute autocomplete prevents form data from being cached in older browsers:


XML
<input type="text" name="foo" autocomplete="off" />
   
try to this,it's working
@Html.TextBox("strPassword", null, new {@autocomplete="off"}
   
<script type="text/javascript">
    function emptytext() {
        var password = document.getElementById('Password');
        if (password.hasAttribute('readonly')) {
            password.removeAttribute('readonly');
            password.blur();
            password.focus();
        }
    }
    function emptypass(me) {
        var userName0 = document.getElementById('UserName0');
        if (userName0.hasAttribute('readonly')) {
            userName0.removeAttribute('readonly');
            userName0.blur();
            userName0.focus();
        }
    }
    function emptypass2() {
        var password0 = document.getElementById('Password0');
        if (password0.hasAttribute('readonly')) {
            password0.removeAttribute('readonly');
            password0.blur();
            password0.focus();
        }
    }
   </script>
<div id="Login-body" class="clearfix">
    <ul>
        <li>
            <span>UserName: </span>
            <input id="UserName0" readonly="readonly" onmouseover="emptytext();">
        </li>
        <li>
            <span>Password: </span>
            <input id="Password" type="password" readonly="readonly" onmouseover="emptypass();">
        </li>
        <li>
            <span>Confirm Password: </span>
            <input type="password" id="Password0" readonly="readonly" onmouseover="emptypass2();">
        </li>
    </ul>
</div>
   
Comments
Dave Kreskowiak 16-Feb-19 9:42am
   
Unexplained code snippets are not really an answer.
Place below code above your username control. This will work in call the browser.

<div style="margin-left:-99999px; height:0px;width:0px;">
<input type="text" id="cc" name="cc" autocomplete="off">
<input type="password" id="cc1" name="cc" autocomplete="off">
</div>
   

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