Example of Password Strength in ASP.NET MVC ProgressBar Control
This sample illustrates a circular and linear progress bar to demonstrate dynamic update based on text box input values.
@Html.UiTextBox("progresslinearpassword", null, new UiTextBoxOptions { Label = "New Password", Type = UiTextBoxType.Password, FloatLabelType = UiFloatLabelType.Auto, CssClass = "ui-input-outlined", OnInput = "inputLinear" })
@Html.UiTextBox("progresspassword", null, new UiTextBoxOptions { Label = "New Password", Type = UiTextBoxType.Password, FloatLabelType = UiFloatLabelType.Auto, CssClass = "ui-input-outlined", OnInput = "inputRing" })
@Html.UiProgressBar(new UiProgressBarOptions { Id = "progresscontainer", Type = UiProgressType.Circular, Value = 0, Maximum = 16, Width = "34px", Thickness = 3, Label = "Password length" })
@Html.UiProgressBar(new UiProgressBarOptions { Id = "progresslinearcontainer", Value = 0, Maximum = 16, SegmentCount = 4, Thickness = 6, Label = "Password strength" })
<style>
.pb-wrap { max-width: 760px; margin: 0 auto; padding: 20px 0; }
.pb-label { margin: 18px 0 6px; font-size: 14px; font-weight: 500; }
.pb-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 28px; padding: 20px 0; }
.pb-row figure { margin: 0; text-align: center; }
.pb-row figcaption { margin-top: 8px; font-size: 13px; }
.pb-center { text-align: center; padding: 16px 0; }
.annotaion-pro { font-size: 20px; font-weight: 700; }
</style>
<div class="control-section">
<div class="pb-wrap">
<div class="pb-row" style="justify-content: flex-start; align-items: center">
@Html.UiTextBox("progresslinearpassword", null, new UiTextBoxOptions { Label = "New Password", Type = UiTextBoxType.Password, FloatLabelType = UiFloatLabelType.Auto, CssClass = "ui-input-outlined", OnInput = "inputLinear" })
@Html.UiTextBox("progresspassword", null, new UiTextBoxOptions { Label = "New Password", Type = UiTextBoxType.Password, FloatLabelType = UiFloatLabelType.Auto, CssClass = "ui-input-outlined", OnInput = "inputRing" })
@Html.UiProgressBar(new UiProgressBarOptions { Id = "progresscontainer", Type = UiProgressType.Circular, Value = 0, Maximum = 16, Width = "34px", Thickness = 3, Label = "Password length" })
</div>
<div class="pb-label" style="max-width: 340px">
@Html.UiProgressBar(new UiProgressBarOptions { Id = "progresslinearcontainer", Value = 0, Maximum = 16, SegmentCount = 4, Thickness = 6, Label = "Password strength" })
</div>
<div id="label" class="pb-center" aria-live="polite"></div>
</div>
</div>
<script>
// Syncfusion: the ring fills with the length of the password, the four segments with its strength
function strength(text) {
var score = 0;
if (text.length >= 8) { score += 4; }
if (/[a-z]/.test(text) && /[A-Z]/.test(text)) { score += 4; }
if (/\d/.test(text)) { score += 4; }
if (/[^A-Za-z0-9]/.test(text)) { score += 4; }
return score;
}
function inputRing(value) { window.Lumen.get('progresscontainer').setValue(Math.min(String(value).length, 16)); }
function inputLinear(value) {
var score = strength(String(value));
window.Lumen.get('progresslinearcontainer').setValue(score);
var names = ['', 'Weak', 'Fair', 'Good', 'Strong'];
document.getElementById('label').textContent = String(value).length ? 'Password strength: ' + names[score / 4] : '';
}
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class ProgressBarController : Controller
{
// The page is Views/ProgressBar/Password.cshtml; it draws what ViewData holds.
public ActionResult Password()
{
return View();
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
This demo for Essential JS2 Progress Bar control shows the dynamic update of linear and circular progress bar.