Monday, June 20, 2022

How to create random hashing in ASP.NET C#

 private void CreateRandomHashing()

        {

            Random rd = new Random();

            Session["rnumb"] = rd.Next();

            rno = Convert.ToString(Session["rnumb"]);


            btnResetPwd.Attributes.Add("onClick", "return chkfrm('" + rno + "');");

            

        }


------------------------------------

aspx page code

function chkfrm() {

debugger;


//Password check for NEW passwprd

if (document.getElementById('<%= txtPassword.ClientID %>').value.length < 6) {

alert("Password must contain at least Six characters!!");

document.getElementById('<%= txtPassword.ClientID %>').focus();

return false;

}

re = /[0-9]/;

if (!re.test(document.getElementById('<%= txtPassword.ClientID %>').value)) {

alert("Password must contain at least one number (0-9)!!");

document.getElementById('<%= txtPassword.ClientID %>').focus();

return false;

}

re = /[a-z]/;

if (!re.test(document.getElementById('<%= txtPassword.ClientID %>').value)) {

alert("Password must contain at least one lowercase letter (a-z)!!");

document.getElementById('<%= txtPassword.ClientID %>').focus();

return false;

}

re = /[A-Z]/;

if (!re.test(document.getElementById('<%= txtPassword.ClientID %>').value)) {

alert("Password must contain at least one uppercase letter (A-Z)!!");

document.getElementById('<%= txtPassword.ClientID %>').focus();

return false;

}

re = /[\W_]/;

if (!re.test(document.getElementById('<%= txtPassword.ClientID %>').value)) {

alert("Password must contain at least one Special Charater!!");

document.getElementById('<%= txtPassword.ClientID %>').focus();

return false;

}



if (document.getElementById('<%=txtPassword.ClientID %>').value != "") {

var md5encypt = MD5(document.getElementById('<%= txtPassword.ClientID %>').value);

document.getElementById('<%=txtPassword.ClientID %>').value = md5encypt;

}


if (document.getElementById('<%=txtConfirmPassword.ClientID %>').value != "") {

var md5encypt = MD5(document.getElementById('<%=txtConfirmPassword.ClientID %>').value);

document.getElementById('<%=txtConfirmPassword.ClientID %>').value = md5encypt;

}

return true;

}

No comments:

Post a Comment