Thursday, July 2, 2009

Gridview Tips and Tricks

http://www.dotnetcurry.com/ShowArticle.aspx?ID=107

generating random passwords

using System;
using System.Data;
using System.Configuration;
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 _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
Label1.Text = "Please enter a password length (e.g. 8)";
}
TextBox1.Text = "8";
}

public static string CreateRandomPassword(int PasswordLength)
{
string _allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789";
Random randNum = new Random();
char[] chars = new char[PasswordLength];
int allowedCharCount = _allowedChars.Length;

for (int i = 0; i < PasswordLength; i++)
{
chars[i] = _allowedChars[(int)((_allowedChars.Length) * randNum.NextDouble())];
}

return new string(chars);
}

protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text != "")
{
string myInt = TextBox1.Text.ToString();
Label1.Text = "Your generated password is: " + CreateRandomPassword(int.Parse(myInt));
}
}
}

Validation Controls Tips and Tricks

http://www.dotnetcurry.com/ShowArticle.aspx?ID=121