<html>
<head>
<title>Funktionskapselung, if und switch bei unsicherem Passwortcheck</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="JavaScript">
<!--
function checkLogin()
{
   // Regular Expression f�r das Eingabefeld Benutzername
   // Regeln wie bei der TGM-Kennung
   var re_uid=/^[a-zA-Z0-9]{2,}\.[a-zA-Z0-9]{2,}$/;

   // Regular Expression f�r das optionale Eingabefeld email
   var re_email=/^[a-zA-Z0-9]{2,}\.[a-zA-Z0-9]{2,} tgm\.ac\.at$/;

   // Regular Expression f�r das Eingabefeld Passwort
   var re_pwd=/^[a-zA-Z0-9����\.:!�\$%&\/(){}\[\]]{5,}$/;

   // Daten von der HTML-Oberfl�che auf lokale Variablen speichern
   var user=document.inputForm.uid.value;
   var email=document.inputForm.email.value;
   var password=document.inputForm.pwd.value;
  
   if (user.length == 0)
   {
      alert("Benutzername fehlt");
      return;
   }
   else
   {  
      // diese L�sung funktioniert bei MS-Internet-Explorer nicht korrekt
      // var SucheUid = new RegExp(re_uid);
      // if (!SucheUid.test(user))
      if (!re_uid.test(user))
      {
         alert("Benutzername syntaktisch fehlerhaft");
         return;
      }
   } 

   if (email.length != 0)
   {
      // diese L�sung funktioniert bei MS-Internet-Explorer nicht korrekt
      // var SucheEmail = new RegExp(re_email);
      // if (!SucheEmail.test(email))
      if (!re_email.test(email))
      {
         alert("E-Mail syntaktisch fehlerhaft");
         return;
      }

   }

   if (password.length == 0)
   {
      alert("Passwort fehlt");
      return;
   }
   else
   {
      // diese L�sung funktioniert bei MS-Internet-Explorer nicht korrekt
      // var SuchePwd = new RegExp(re_pwd);
      // if (!SuchePwd.test(password))
      if (!re_pwd.test(password))
      {
         alert("Passwort syntaktisch fehlerhaft");
         return;
      }
   } 
    
   if (!checkPw(user, password))
   {
      alert("Passwortpr�fung negativ");
      return;
   }
  
   document.write("<b>Benutzeranmeldung erfolgreich !</b><br><br>");
   document.write("<b>Benutzername : </b>" + user + "<br>");
   document.write("<b>E-Mail : </b>" + email + "<br>");
   document.write("<b>Passwort : </b>" + password + "<br>");

   return;
}

function checkPw(uid,pwd)
{
   // inhaltliche Pr�fung des Passwortes
   switch(uid)
   {
      case "herbert.koenig":
         fixed_pwd="pcz123";   
      break;
      case "PCZ.TGM":
         fixed_pwd="schule";   
      break;
      case "pcz.tgm":
         fixed_pwd="schule";   
      break;
      default:
         // Fehler: unbekannter Benutzer
         return false;
      break;
   }
 
   if (fixed_pwd != pwd)
   {
      // Fehler: falsches Passwort
      return false;
   }
   else
   {
      // Passwort�berpr�fung OK
      return true;
   }
}
//-->
</script>
</head>

<body bgcolor="#FFFFFF" text="#000000">

<form name="inputForm">
  <table border="0" cellspacing="5" cellpadding="0">
    <tr>
      <td align="right">Benutzername *</td>
      <td>
        <input type="text" name="uid">
      </td>
      <td>&nbsp;</td>
    </tr>
<tr>
      <td align="right">E-Mail</td>
      <td>
        <input type="text" name="email">
      </td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td align="right">Passwort *</td>
      <td>
        <input type="password" name="pwd">
        <input type=button value="Login"  onClick="checkLogin()">
      </td>
      <td>
      </td>
    </tr>
  </table>

</form>
*  Pflichteingabefeld
</body>
</html>