Password auf Groß-/Kleinschreibung und Sicherheit prüfen

Was mir gerade noch aufgefallen ist: du bist nachlässig mit der Verwendung von Semikolons. Setz die mal bitte noch an den entsprechenden Stellen.

Am besten den Quellcode hier kontrollieren lassen.
*lol*

http://www.jslint.com/ hat gesagt.:
Error:

Problem at line 4 character 30: Missing semicolon.

show += password.length * 4

Problem at line 5 character 71: Missing semicolon.

show += ( checkRepetition(1,password).length - password.length ) * 1

Problem at line 6 character 71: Missing semicolon.

show += ( checkRepetition(2,password).length - password.length ) * 1

Problem at line 7 character 71: Missing semicolon.

show += ( checkRepetition(3,password).length - password.length ) * 1

Problem at line 8 character 71: Missing semicolon.

show += ( checkRepetition(4,password).length - password.length ) * 1

Problem at line 9 character 51: Expected '{' and instead saw 'show'.

if (password.match(/(.*[0-9].*[0-9].*[0-9])/)) show += 5

Problem at line 9 character 60: Missing semicolon.

if (password.match(/(.*[0-9].*[0-9].*[0-9])/)) show += 5

Problem at line 10 character 37: Unescaped '^'.

if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/))...

Problem at line 10 character 62: Unescaped '^'.

if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/))...

Problem at line 10 character 79: Expected '{' and instead saw 'show'.

if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/))...

Problem at line 10 character 88: Missing semicolon.

if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/))...

Problem at line 11 character 57: Expected '{' and instead saw 'show'.

if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) show += 5

Problem at line 11 character 66: Missing semicolon.

if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) show += 5

Problem at line 12 character 67: Expected '{' and instead saw 'show'.

if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/)) show += 10

Problem at line 12 character 77: Missing semicolon.

if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/)) show += 10

Problem at line 13 character 35: Unescaped '^'.

if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/...

Problem at line 13 character 82: Expected '{' and instead saw 'show'.

if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/...

Problem at line 13 character 92: Missing semicolon.

if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/...

Problem at line 14 character 35: Unescaped '^'.

if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z...

Problem at line 14 character 85: Expected '{' and instead saw 'show'.

if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z...

Problem at line 14 character 95: Missing semicolon.

if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z...

Problem at line 15 character 61: Expected '{' and instead saw 'show'.

if (password.match(/^\w+$/) || password.match(/^\d+$/) ) show -= 10

Problem at line 15 character 71: Missing semicolon.

if (password.match(/^\w+$/) || password.match(/^\d+$/) ) show -= 10

Problem at line 29 character 25: 'checkRepetition' was used before it was defined.

function checkRepetition(pLen,str) {

Problem at line 30 character 11: Missing semicolon.

res = ""

Problem at line 32 character 22: Missing semicolon.

repeated=true

Problem at line 34 character 13: Expected '{' and instead saw 'repeated'.

repeated=repeated && (str.charAt(j+i)==str.charAt(j+i+pLen))

Problem at line 34 character 73: Missing semicolon.

repeated=repeated && (str.charAt(j+i)==str.charAt(j+i+pLen))

Problem at line 35 character 21: Expected '{' and instead saw 'repeated'.

if (j<pLen) repeated=false

Problem at line 35 character 35: Missing semicolon.

if (j<pLen) repeated=false

Problem at line 37 character 22: Missing semicolon.

i+=pLen-1

Problem at line 38 character 27: Missing semicolon.

repeated=false

Problem at line 41 character 31: Missing semicolon.

res+=str.charAt(i)

Problem at line 44 character 15: Missing semicolon.

return res

Implied global: password 3,4,5,6,7,8,9,10,11,12,13,14,15, breite 20,21,23,24,26, document 26, res 30,41,44, i 31,33,34,37,41, repeated 32,34,35,36,38, j 33,34,35

mfg Maik
 
ja ok <:

Ich hab es mal durchlaufen lassen und die meisten Fehler beseitigt. Das Ergebniss sieht jetzt wie folgt aus:

Code:
function chkpass() {
  if((document.getElementById("password1").value != "") && (document.getElementById("password1").value != "")) {
    if(document.getElementById("password2").value == document.getElementById("password1").value) {
      document.getElementById("passchk").innerHTML = "<img src=\"sys/images/ok.gif\" /> Die Passw&ouml;rter stimmen &uuml;berein.";
    } else {
      document.getElementById("passchk").innerHTML = "<img src=\"sys/images/fail.gif\" /> Die Passw&ouml;rter stimmen nicht &uuml;berein.";
    }
  }
}

function checkRepetition(pLen,str) {
  res = "";
  for ( i=0; i<str.length ; i++ ) {
    repeated=true;
    for (j=0;j < pLen && (j+i+pLen) < str.length;j++) {
      repeated=repeated && (str.charAt(j+i)==str.charAt(j+i+pLen));
    }
    if (j<pLen) {
      repeated=false;
    }
    if (repeated) {
      i+=pLen-1;
      repeated=false;
    }
    else {
      res+=str.charAt(i);
    }
  }
  return res;
}

function chksav(obj) {
  var show = 0;
  var passfullsave = 0;
  password = obj.value;
  show += password.length * 4;
  show += ( checkRepetition(1,password).length - password.length ) * 1;
  show += ( checkRepetition(2,password).length - password.length ) * 1;
  show += ( checkRepetition(3,password).length - password.length ) * 1;
  show += ( checkRepetition(4,password).length - password.length ) * 1;
  if (password.match(/(.*[0-9].*[0-9].*[0-9])/)) { 
    show += 5; 
  }
  if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) { 
    show += 5; 
  }
  if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) { 
    show += 5;
  }
  if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/)) { 
    show += 10; 
  }
  if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/)) { 
    show += 10; 
  }
  if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z])/)) { 
    show += 10; 
  }
  if (password.match(/^\w+$/) || password.match(/^\d+$/) ) { 
    show -= 10; 
  }
  if (show < 0) {
    show = show * -1;
  }
  if (show < 101) {
    breite = show * 4;
    breite = breite + "px";
  } else {
    passfullsave = 1;
    breite = 400;
    breite = breite + "px";
  }
  document.getElementById("passwordsicherheit").style.width = breite;  
  if(password.length != 0) {
    if(password.length < 6) {
      passtext = "Das Passwort ist zu kurz.";
    } else {
      if(show <= 25) {
        passtext = "Unsicher!";
      } else {
        if((show >= 26) && (show <= 50)) {
          passtext = "Weniger sicher!";
        } else {
          if((show >= 51) && (show <= 75)) {
            passtext = "Sicher";
          } else {
            if((show >= 76) && (show <= 101)) {
              passtext = "Sehr sicher!";
            } else {
              passtext = "";
            }
          }
        }
      }
    }
  } 
  if(passfullsave == 1) {
    passtext = "Un&uuml;bertroffen sicher!";
  }
  document.getElementById("passtext").innerHTML = "<i>" + passtext + "</i>";
}

Ich bekomme jetzt noch folgende fehler:

Code:
Error:

Problem at line 44 character 37: Unescaped '^'.

if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) {

Problem at line 44 character 62: Unescaped '^'.

if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) {

Problem at line 53 character 35: Unescaped '^'.

if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/...

Problem at line 56 character 35: Unescaped '^'.

if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z...

Problem at line 74 character 22: Use '!==' to compare with '0'.

if(password.length != 0) {

Implied global: document 2,3,4,6,73,100, res 12,26,29, i 13,15,16,22,26, repeated 14,16,19,21,23, j 15,16,18, password 35,36,37,38,39,40,41,44,47,50,53,56,59,74,75, breite 66,67,70,71,73, passtext 76,79,82,85,88,90,98,100

Global checkRepetition, chkpass, chksav

1-9 chkpass()

11-30 checkRepetition(pLen, str)

32-101 chksav(obj)
Variable passfullsave, show
Global checkRepetition

/*members charAt, getElementById, innerHTML, length, match, style, value, 
    width
*/

Trotzdem funktioniert es im Internet Explorer immernoch nicht :/
 
Moin,


Das circumflex hat in Zeichenklassen eine spezielle Bedeutung(es dient der Negation der Zeichenklasse). Daher muss es escaped werden, wenn du es nicht mit dieser speziellen Bedeutung einsetzt, was auch die Fehlermeldungen besagen.

Es ist übrigens nicht vonnöten, die einzelnen Zeichen mit Kommas zu trennen...ein Komma ist in RegExp ein Komma und kein Separator(mal ausgenommen die Verwendung zur Längenangabe eines Suchmusters)
 
Ich hab es jetzt escaped und laut JSLint nurnoch folgenden Fehler:

Error:

Implied global: document 2,3,4,6,73,100, res 12,26,29, i 13,15,16,22,26, repeated 14,16,19,21,23, j 15,16,18, password 35,36,37,38,39,40,41,44,47,50,53,56,59,74,75, breite 66,67,70,71,73, passtext 76,79,82,85,88,90,98,100

Im IE geht es aber leider immernoch nicht :( Der Fehlerdialog gibt aus:

Zeile: 36
Zeichen: 3
Fehler: Das Objekt unterstütz diese Eigenschaft oder Methode nicht
Code: 0
URL: http://localhost/index.php?site=register

Die Zeile wäre dann -> show += password.length * 4;

Code:
function chkpass() {
  if((document.getElementById("password1").value != "") && (document.getElementById("password1").value != "")) {
    if(document.getElementById("password2").value == document.getElementById("password1").value) {
      document.getElementById("passchk").innerHTML = "<img src=\"sys/images/ok.gif\" /> Die Passw&ouml;rter stimmen &uuml;berein.";
    } else {
      document.getElementById("passchk").innerHTML = "<img src=\"sys/images/fail.gif\" /> Die Passw&ouml;rter stimmen nicht &uuml;berein.";
    }
  }
}

function checkRepetition(pLen,str) {
  res = "";
  for ( i=0; i<str.length ; i++ ) {
    repeated=true;
    for (j=0;j < pLen && (j+i+pLen) < str.length;j++) {
      repeated=repeated && (str.charAt(j+i)==str.charAt(j+i+pLen));
    }
    if (j<pLen) {
      repeated=false;
    }
    if (repeated) {
      i+=pLen-1;
      repeated=false;
    }
    else {
      res+=str.charAt(i);
    }
  }
  return res;
}

function chksav(obj) {
  var show = 0;
  var passfullsave = 0;
  password = obj.value;
  show += password.length * 4;
  show += ( checkRepetition(1,password).length - password.length ) * 1;
  show += ( checkRepetition(2,password).length - password.length ) * 1;
  show += ( checkRepetition(3,password).length - password.length ) * 1;
  show += ( checkRepetition(4,password).length - password.length ) * 1;
  if (password.match(/(.*[0-9].*[0-9].*[0-9])/)) { 
    show += 5; 
  }
  if (password.match(/(.,*[!@#$%\^&*?_~].,*[!@#$%\^&*?_~])/)) { 
    show += 5; 
  }
  if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) { 
    show += 5;
  }
  if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/)) { 
    show += 10; 
  }
  if (password.match(/([!@#$%\^&*?_~].,)/) && password.match(/([0-9])/)) { 
    show += 10; 
  }
  if (password.match(/([!@#$%\^&*?_~.,])/) && password.match(/([a-zA-Z])/)) { 
    show += 10; 
  }
  if (password.match(/\^\w+$/) || password.match(/\^\d+$/) ) { 
    show -= 10; 
  }
  if (show < 0) {
    show = show * -1;
  }
  if (show < 101) {
    breite = show * 4;
    breite = breite + "px";
  } else {
    passfullsave = 1;
    breite = 400;
    breite = breite + "px";
  }
  document.getElementById("passwordsicherheit").style.width = breite;  
  if(password.length !== 0) {
    if(password.length < 6) {
      passtext = "Das Passwort ist zu kurz.";
    } else {
      if(show <= 25) {
        passtext = "Unsicher!";
      } else {
        if((show >= 26) && (show <= 50)) {
          passtext = "Weniger sicher!";
        } else {
          if((show >= 51) && (show <= 75)) {
            passtext = "Sicher";
          } else {
            if((show >= 76) && (show <= 101)) {
              passtext = "Sehr sicher!";
            } else {
              passtext = "";
            }
          }
        }
      }
    }
  } 
  if(passfullsave == 1) {
    passtext = "Un&uuml;bertroffen sicher!";
  }
  document.getElementById("passtext").innerHTML = "<i>" + passtext + "</i>";
}

Ich werd noch verrückt :(

lg weedo
 

Neue Beiträge

Zurück