RANDOM PASSWORD GENERATION ASPX PAGE
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RandomPassword.aspx.cs" Inherits="RandomPassword" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<div>Enter Password length: <asp:TextBox ID="txtPassLength" runat="server"></asp:TextBox><asp:Button ID="btnGenerate" runat="server" Text="Generate" OnClick="btnGenerate_Click" /></div>
<div>Random Password: <asp:TextBox ID="txtPassword" runat="server"></asp:TextBox></div>
</div>
<br /><br />
<div>
<b>Coding Support Provided By <a href="http://www.top54u.com">www.top54u.com</a><br />
<a href="http://programming.top54u.com">Programming Ezine</a></b><br />
<br />
</div>
</form>
</body>
</ht
CODE BEHIND PAGE
-------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class RandomPassword : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnGenerate_Click(object sender, EventArgs e)
{
string allowedChars = "";
allowedChars = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,";
allowedChars += "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,";
allowedChars += "1,2,3,4,5,6,7,8,9,0,!,@,#,$,%,&,?";
char[] sep ={ ',' };
string[] arr = allowedChars.Split(sep);
string passwordString = "";
string temp = "";
Random rand = new Random();
for (int i = 0; i < Convert.ToInt32(txtPassLength.Text); i++)
{
temp = arr[rand.Next(0, arr.Length)];
passwordString += temp;
}
txtPassword.Text = passwordString;
}
}
Tuesday, July 7, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment