SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    Don't get too close, I bite! Nicky's Avatar
    Join Date
    Jul 1999
    Location
    Lancashire, UK
    Posts
    8,277
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Comparing Two Password Strings

    I have not done any programming in years adn someone asked me this today:
    "I wanna compare two password strings.
    I don't think I can use
    IF (pass1 == pass2) equal to
    because they are not numerical I certainly cant use
    IF (pass1 <> pass2) not equal to
    so how do I check that pass1 is the same as pass2."

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2000
    Location
    Chico, Ca
    Posts
    1,125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What lanaguage are you refering to?
    "Happiness doesn't find you, you find happiness" -- Unknown
    www.chuckknows.com

  3. #3
    Don't get too close, I bite! Nicky's Avatar
    Join Date
    Jul 1999
    Location
    Lancashire, UK
    Posts
    8,277
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Javascript.

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2000
    Location
    Chico, Ca
    Posts
    1,125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    opps didn't notice it was in the Javascipt forum

    If it was .net I could help ya..
    "Happiness doesn't find you, you find happiness" -- Unknown
    www.chuckknows.com

  5. #5
    Under Construction Poop_Shoot's Avatar
    Join Date
    Jul 2003
    Location
    Sacramento, CA
    Posts
    330
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Nicky The first one is correct!

    Code:
    var myString="hello"
    if("hello"==myString){
    staments to execute if true!
    }
    else{
    statments to execute if false!
    }

  6. #6
    Under Construction Poop_Shoot's Avatar
    Join Date
    Jul 2003
    Location
    Sacramento, CA
    Posts
    330
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry I didnt completly read your post! It should compare them both the same if its a string, number, or boolean!

    Code:
    var myString=parseInt(20,10);
    if(20==myString){
    staments to execute if true!
    }
    else{
    statments to execute if false!
    }
    Code:
    var myString=true;
    if(true==myString){
    staments to execute if true!
    }
    else{
    statments to execute if false!
    }

  7. #7
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    As poop_shoot implies, comparision is virtually the same regardless of primitive type. So,
    Code:
    if (pass1 == pass2)
    is correct. If you are having a problem with that -- and the code you posted is the code you used -- it is because "IF" is not the same as "if".

    poop_shoot:
    Code:
    var isOK = true;
     if(isOK)
     {
       statements to execute if true! 
     }
     else
     { 
       statements to execute if false! 
     } 
    You don't need to compare booleans.
    Code:
      var isOK = false;
      if (! isOK)
      {
    	statements for false condition
      }
    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  8. #8
    Under Construction Poop_Shoot's Avatar
    Join Date
    Jul 2003
    Location
    Sacramento, CA
    Posts
    330
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks vinny I posted that kind of hastly! Thanx 4 pointing out what I missed!

  9. #9
    SitePoint Zealot Arkkimaagi's Avatar
    Join Date
    Mar 2002
    Location
    Lappeenranta, Finland
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nikcy D

    like they said,
    if (pass1 == pass2) {}
    is correct.

    if you want to see if passwords are not the same, use
    if (pass1 != pass2) {}

    this works with numbers, strings, etc.

    var pass1 = "test";
    var pass2 = "test";
    if(pass1 == pass2){
    alert("ok");
    }else{
    alert("not ok");
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •