tags:

views:

91

answers:

4

I have a password and confirm password field and I dont want the user to simply copy from the first field and paste in the later field.What should I do for this??

+1  A: 

There is no effective way to stop this that works on all browsers. Even if such a solution existed, a user could just disable JavaScript and just copy and paste if desired. Most users won't copy and paste though, as it's for their own benefit and is to prevent mistakes.

Delan Azabani
Yes there is, but of course if you disable javascript you can not make it work...
Aristos
It is still wrong as it's a impediment of the users' freedom. If the user wants to copy and paste, let her do it (it's only her own fault if she gets the password wrong).
Delan Azabani
@Delan Ok this is a different discussion... I will make a question on ui forum.
Aristos
+2  A: 

Copy functionality is usually disabled for password-type fields, so you don't need to do anything. There is nothing to stop a user pasting the same text into both fields from elsewhere, however, and there isn't a lot you can do about it. Trying to prevent this would stop some users who want to be sure they have their password right from pasting it in, as well as users that use password generators.

Dave
@Dave I agree for the paste from password generator, that why what I have made is NOT for the password, but for the email field ! :)
Aristos
+3  A: 

Here is a way...

<asp:TextBox ID="txtEMailVerifyJoin" runat="server" ClientIDMode="Static"       
    autocomplete="off" 
    onpaste="pasteEvent('reg_conf_email');return false;" 
    onkeydown="disablePaste('pasteEvent()','reg_conf_email');" 
    onkeyup="disablePaste('pasteEvent()','reg_conf_email');" 
    oninput="disablePaste('pasteEvent()','reg_conf_email');"        
    ></asp:TextBox>

And for javascript

<script>
    var charCount = document.getElementById("txtEMailVerifyJoin").value.length;
    var oldVal = eval(document.getElementById("txtEMailVerifyJoin")).value;

function disablePaste(methodToCall)
{  
    newCharCount = document.getElementById("txtEMailVerifyJoin").value.length;  
    oldCharCount = charCount;    
    charCount = newCharCount;  

    if(newCharCount - oldCharCount > 1) 
    {   
        eval(methodToCall);    
        charCount = oldVal.length;  
    }  
    else  
    {     
        oldVal = eval(document.getElementById("txtEMailVerifyJoin")).value;  
    } 
}

function pasteEvent()
{   
    document.getElementById("txtEMailVerifyJoin").value=oldVal;  
    return false;
}

function initDisablePaste()
{  
    charCount = document.getElementById("txtEMailVerifyJoin").value.length;  
    oldVal = eval(document.getElementById("txtEMailVerifyJoin")).value;
}

initDisablePaste();
</script>

Its not mine idea, if I find where I see it I will post it here.

See it live here: Join Athineon

this command works (for this page) on the Confirm email address ! (not for the password)

About the user interface and if this is a good idea, I make a question here: http://ui.stackexchange.com/questions/1488/wondering-if-i-must-let-a-user-copy-paste-the-double-asking-confirm-e-mail-on-the

Aristos
+2  A: 

simple in the password mode user cannot copy the text and cannot paste it in other text box. so your problem get solved .give the both the textBox in password mode