Fork me on GitHub

Bootstrap Strength Meter

Bootstrap Strength Meter is intended to demonstrate the usage of Password Score - a JavaScript library used to give a realistic estimate of the strength of a password.

Consider donating to support development.

Note that documentation is not complete yet. Check boostrap-strength-meter for details!

  1. Include Required Files

    First, all dependencies need to be included: jQuery, Twitter Bootstrap and Password Score.

    <!-- Twitter Bootstrap CSS: -->
    <link rel="stylesheet" type="text/css" href="docs/css/bootstrap.css">
    
    <script type="text/javascript" src="docs/js/jquery.js"></script>
    <script type="text/javascript" src="docs/js/bootstrap.js"></script>
    <script type="text/javascript" src="password-score/dist/js/password-score.js"></script>
    <script type="text/javascript" src="password-score/dist/js/password-score-options.js"></script>
    <script type="text/javascript" src="dist/js/bootstrap-strength-meter.js"></script>
    
  2. Setup Required HTML

    Depending on the used configuration options, the required markup may vary - see Drivers & Options. For this example we assume that the strength of the password should be displayed as text:

    <form class="form-horizontal">
        <div class="form-group">
            <label class="form-label col-sm-2">Email</label>
            <div class="col-sm-10">
                <input type="text" placeholder="Email ..." class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="form-label col-sm-2">Password</label>
            <div class="col-sm-4">
                <input type="text" placeholder="Password ..." class="form-control" id="example-getting-started-input" />
            </div>
            <div class="col-sm-6" id="example-getting-started-text" style="font-weight:bold;padding:6px 12px;">
    
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button class="btn btn-primary">Login</button>
            </div>
        </div>
    </form>
    
  3. Call Plugin

    The plugin offers several so called drivers - options that allow to display the password strength differently. The following example shows how to use the text driver:

    <script type="text/javascript">
        $(document).ready(function() {
            $('#example-getting-started-input').strengthMeter('text', {
                container: $('#example-getting-started-text')
            });
        });
    </script>
    
text driver
The text driver will display the password strength as text - ranging from "ridiculus" over "good" to "very strong" and applying corresponding classes: .text-danger, .text-warning and .text-success. The text driver offers the below configuration options.
container

The container the text is displayed in. Usually, a div or span near the corresponding password input is a good choice. An example can be seen in Getting Started.

Per default, the text will be appended to the password input's parent element.

hierarchy

This option allows to control the text begin displayed and the class being applied on its parent span. The default settings look as follows:

hierarchy: {
    '0': ['text-danger', 'ridiculous'],
    '25': ['text-danger', 'very weak'],
    '50': ['text-warning', 'weak'],
    '75': ['text-warning', 'good'],
    '100': ['text-success', 'strong'],
    '125': ['text-success', 'very strong']
}

The keys refer to the score needed to change the text and its corresponding class. This means that a password with a score between 10 and 20 will be declared as "very weak". For this purpose it is useful to understand what the score means: A score of $h$ means that a maximum of $2^h$ attempts are necessary to crack the password. The higher $h$ the stronger the password.

An example is shown below (where relatively weak passwords are declared "strong"):

<script type="text/javascript">
    $(document).ready(function() {
        $('#example-text-hierarchy-input').strengthMeter('text', {
            container: $('#example-text-hierarchy-text'),
            hierarchy: {
                '0': ['text-danger', 'Think about a stronger password!'],
                '25': ['text-warning', 'Well, you are doing better ...'],
                '50': ['text-warning', 'Keep going ...'],
                '75': ['text-success', 'Ok, this will do!']
            }
        });
    });
</script>
<form class="form-horizontal">
    <div class="form-group">
        <label class="form-label col-sm-2">Password</label>
        <div class="col-sm-4">
            <input type="text" placeholder="Password ..." class="form-control" id="example-hierarchy-input" />
        </div>
        <div class="col-sm-6" id="example-text-hierarchy-text" style="font-weight:bold;padding:6px 12px;">

        </div>
    </div>
</form>
tooltip driver

The tooltip driver will display the password strength in a tooltip.

This driver requires Twitter Bootstrap's tooltip.js to be included.

A basic example of this driver can be seen below.

<script type="text/javascript">
    $(document).ready(function() {
        $('#example-tooltip').strengthMeter('tooltip');
    });
</script>
<form class="form-horizontal">
    <div class="form-group">
        <label class="form-label col-sm-2">Password</label>
        <div class="col-sm-4">
            <input type="text" placeholder="Password ..." class="form-control" id="example-text-hierarchy-input" />
        </div>
    </div>
</form>
hierarchy

This option allows to control the text begin displayed. The default options look as follows:

hierarchy: {
    '0': 'ridiculous',
    '25': 'very weak',
    '50': 'weak',
    '75': 'good',
    '100': 'strong',
    '125': 'very strong'
}

The keys refer to the score needed to change the text. This means that a password with a score between 10 and 20 will be declared as "very weak". For this purpose it is useful to understand what the score means: A score of $h$ means that a maximum of $2^h$ attempts are necessary to crack the password. The higher $h$ the stronger the password.

An example is shown below (where relatively weak passwords are declared "strong"):

<script type="text/javascript">
    $(document).ready(function() {
        $('#example-tooltip-hierarchy').strengthMeter('tooltip', {
            hierarchy: {
                '0': ['Think about a stronger password!'],
                '25': ['Well, you are doing better ...'],
                '50': ['Keep going ...'],
                '75': ['Ok, this will do!']
            },
            tooltip: {
                viewport: '#example-tooltip-hierarchy-viewport'
            }
        });
    });
</script>
<form class="form-horizontal">
    <div class="form-group">
        <label class="form-label col-sm-2">Password</label>
        <div class="col-sm-4" id="example-tooltip-hierarchy-viewport">
            <input type="text" placeholder="Password ..." class="form-control" id="example-tooltip-hierarchy" />
        </div>
    </div>
</form>
progressBar driver

The progressBar driver will visualize the password strength as progress bar.

A basic example is shown below.

<script type="text/javascript">
    $(document).ready(function() {
        $('#example-progress-bar').strengthMeter('progressBar', {
            container: $('#example-progress-bar-container')
        });
    });
</script>
<form class="form-horizontal">
    <div class="form-group">
        <label class="form-label col-sm-2">Password</label>
        <div class="col-sm-4">
            <input type="text" placeholder="Password ..." class="form-control" id="example-progress-bar" />
        </div>
    </div>
    <div class="form-group">
        <label class="form-label col-sm-2">Password Strength</label>
        <div class="col-sm-4" id="example-progress-bar-container">

        </div>
    </div>
</form>
container

The container element the progress bar is appended to.

An example can be found above.

hierarchy

This option allows to control the color of the progress bar. The default option looks as follows:

hierarchy: {
    '0': 'progress-bar-danger',
    '50': 'progress-bar-warning',
    '100': 'progress-bar-success'
}
                                    

The keys refer to the score needed in order to change the color of the pgroess bar. This means that a password with a score between 0 and 25 is depicted as red (progress-bar-danger). For this purpose it is useful to understand what the score means: A score of $h$ means that a maximum of $2^h$ attempts are necessary to crack the password. The higher $h$ the stronger the password.

An example is given below:

<script type="text/javascript">
    $(document).ready(function() {
        $('#example-progress-bar-hierarchy').strengthMeter('progressBar', {
            container: $('#example-progress-bar-hierarchy-container'),
            hierarchy: {
                '0': 'progress-bar-danger',
                '25': 'progress-bar-warning',
                '200': 'progress-bar-success'
            }
        });
    });
</script>
<form class="form-horizontal">
    <div class="form-group">
        <label class="form-label col-sm-2">Password</label>
        <div class="col-sm-4">
            <input type="text" placeholder="Password ..." class="form-control" id="example-progress-bar-hierarchy" />
        </div>
    </div>
    <div class="form-group">
        <label class="form-label col-sm-2">Password Strength</label>
        <div class="col-sm-4" id="example-progress-bar-hierarchy-container">

        </div>
    </div>
</form>
BSD 3-Clause License

Copyright (c) 2013 - 2018 David Stutz

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of David Stutz nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


© 2013 - 2020 David StutzBSD 3-Clause LicenseImpressumDatenschutz