File: example4.html

Recommend this page to a friend!
  Classes of Axel Hahn  >  AH JavaScript Password Strength Check  >  example4.html  >  Download  
File: example4.html
Role: Example script
Content type: text/plain
Description: Example script
Class: AH JavaScript Password Strength Check
Calculate and display the strength of a password
Author: By
Last change: added minified version; min version is used in examples now
Date: 2 years ago
Size: 2,878 bytes


Class file image Download
<!DOCTYPE html>
        <title>Demo 4 for password checker</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script src="ahpwcheck.class.min.js"></script>
        <link rel="stylesheet" type="text/css" href="example.css" />
        <h1>Demo 4 for password checker (ahpwcheck.class.js)</h1>
            <a href="example.html">example 1</a>
            <a href="example2.html">example 2</a>
            <a href="example3.html">example 3</a>
            <a href="example4.html" class="active">example 4</a>
            <a href="example5.html">example 5</a>
        <!-- ************************************************************** -->
        <h2>Test password on submit</h2>
        <p class="info">
            A demo to react on submit event of a form:<br>
            Type something and press submit. The you get an alert box that shows
            the score of the entered password using the getScore method.
        <form onsubmit="return mysubmit();">
            <input type="password" id="ePassword">
            <input type="submit" value="Submit">

        <div id="outpwcheck"></div>
        <script id="source">

            var oPwCheck = new ahpwcheck();
            oPwCheck.watch('ePassword', 'outpwcheck');
            function mysubmit(){
                var minScore=0.95; // something close to 1 or 1
                var sPassword=document.getElementById('ePassword').value;
                var score=oPwCheck.getScore(sPassword);
                    alert("Select a better password, please! (score: "+score+")");
                    return false;
                } else {
                    alert("Password is OK. (score: "+score+")");
                    return true;

        <!-- ************************************************************** -->

            The form contains an attribute "onsubmit"
        <pre>&lt;form onsubmit="return mysubmit();"></pre>
            In the function "mysubmit()" we can check the score if it is axactly or close to 1.<br>
            With return false the form will not be sent.<br>
            document.write("<pre>" + document.getElementById("source").innerHTML.replace(/</g, "&lt;") + "</pre>");
        DOCS: <a href="http://www.axel-hahn.de/docs/ahpwcheck/index.htm" target="_blank">http://www.axel-hahn.de/docs/ahpwcheck/index.htm</a>