Generated Password in JavaScript : Generated Password « Security « JavaScript DHTML

Home
JavaScript DHTML
1.Ajax Layer
2.Data Type
3.Date Time
4.Development
5.Document
6.Dojo toolkit
7.Event
8.Event onMethod
9.Ext JS
10.Form Control
11.GUI Components
12.HTML
13.Javascript Collections
14.Javascript Objects
15.Javascript Properties
16.jQuery
17.Language Basics
18.Mochkit
19.Mootools
20.Node Operation
21.Object Oriented
22.Page Components
23.Rico
24.Scriptaculous
25.Security
26.SmartClient
27.Style Layout
28.Table
29.Utilities
30.Window Browser
31.YUI Library
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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.