Generated Password in JavaScript : Generated Password : Security : JavaScript DHTML examples (example source code) Organized by topic

JavaScript DHTML
1. Ajax Layer
2. Data Type
3. Date Time
4. Development
5. Document
6. Event
7. Event onMethod
8. Form Control
9. GUI Components
10. HTML
11. Javascript Collections
12. Javascript Objects
13. Language Basics
14. Node Operation
15. Object Oriented
16. Page Components
17. Security
18. Style Layout
19. Table
20. Utilities
21. Window Browser
Java
Java Tutorial
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
JavaScript DHTML » Security » Generated Password 
Generated Password in JavaScript

<HTML>
  <HEAD>
    <TITLE>Password Generator</TITLE>
    <!--
      CryptoMX Tools
      Copyright (C2004 2006 Derek Buitenhuis

      This program is free software; you can redistribute it and/or
      modify it under the terms of the GNU General Public License
      as published by the Free Software Foundation; either version 2
      of the License, or (at your optionany later version.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.

      You should have received a copy of the GNU General Public License
      along with this program; if not, write to the Free Software
      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    -->
  </head>
  <body>
    <SCRIPT LANGUAGE="JavaScript">
      function GeneratePassword() {

          if (parseInt(navigator.appVersion<= 3) {
              alert("Sorry this only works in 4.0 browsers");
              return true;
          }
          var length=8;
          var sPassword = "";
          length = document.aForm.charLen.value;

          var noPunction = (document.aForm.punc.checked);
          var randomLength = (document.aForm.rLen.checked);

          if (randomLength) {
              length = Math.random();

              length = parseInt(length * 100);
              length = (length % 76
          }


          for (i=0; i < length; i++) {

              numI = getRandomNum();
              if (noPunction) { while (checkPunc(numI)) { numI = getRandomNum()} }

              sPassword = sPassword + String.fromCharCode(numI);
          }

          document.aForm.passField.value = sPassword

          return true;
      }

    function getRandomNum() {

          // between 0 - 1
          var rndNum = Math.random()

          // rndNum from 0 - 1000
          rndNum = parseInt(rndNum * 1000);

          // rndNum from 33 - 127
          rndNum = (rndNum % 9433;

          return rndNum;
      }

      function checkPunc(num) {

          if ((num >=33&& (num <=47)) { return true}
          if ((num >=58&& (num <=64)) { return true}
          if ((num >=91&& (num <=96)) { return true}
          if ((num >=123&& (num <=126)) { return true}

          return false;
      }
    </SCRIPT>
    <FORM NAME="aForm">
      <TABLE>
        <TR>
          <TD>
            Generated Password:<BR>
            <INPUT TYPE="text" NAME="passField" VALUE="" SIZE="40"><BR>
          </TD>
          <TD>
            # of chars<BR>
            &nbsp;&nbsp;<INPUT TYPE="text" NAME="charLen" VALUE="8" SIZE="3">
          </TD>
        </TR>
        <TR>
          <TD>
            <INPUT TYPE="checkbox" NAME="punc" CHECKED> No Punctuation Marks <BR>
            <INPUT TYPE="checkbox" NAME="rLen"> Random Length (12<BR>
          </TD>
        </TR>
        <TR>
          <TD COLSPAN="2" ALIGN=CENTER>
            <br>
            <INPUT TYPE="button" VALUE=" Generate Password " onClick="GeneratePassword()">
          </TD>
        </TR>
      </TABLE>
    </FORM>
  </BODY>
</HTML>
           
       
Related examples in the same category
Home | Contact Us
Copyright 2003 - 07 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.