How to generate random password in asp.net c#

In this article, we learn about how to generate the random password using Membership.GeneratePasswordMethod.

Design:-



Source Code:-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="randomgeneratepassword.aspx.cs"
    Inherits="randomgeneratepassword" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <fieldset style="width: 200px;">
        <legend>Random Generate Password</legend>
        <asp:TextBox ID="txtpwd" placeholder=" Auto Generated Password" runat="server" Width="180px"></asp:TextBox>
        <br />
        <br />
     
        <asp:Button ID="btngeratedpwd" runat="server" Text="Generated Password"
            Width="180px" onclick="btngeratedpwd_Click"
             />
        <br />
    </form>
</body>
</html>


Code behind:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class randomgeneratepassword : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btngeratedpwd_Click(object sender, EventArgs e)
    {

        String pwd = Membership.GeneratePassword(11, 2);
        txtpwd.Text = pwd;

    }
}

Out-Put:-





How to generate random password in asp.net c# How to generate random password in asp.net c# Reviewed by NEERAJ SRIVASTAVA on 6:22:00 PM Rating: 5

No comments:

Powered by Blogger.