How to use Asp.net
  • Home
  • About us
  • Disclaimer
  • joy of helping
KEEP IN TOUCH

Monthly archives for August, 2011

Alpha Numeric Digit Numbers for password asp.net

Aug29
2011
Leave a Comment Written by vikram

Well here I m going to explain how can we generate random DIGITS No. and also Random ALPHA NUMERIC DIGITS No. for password. Hope it will help you.

for random numbers click:-  here

Create a method name Pin_password().

public string Pin_password(string rec)
{
string pin_pwd = string.Empty;
int j = 0;      //for Upper Case because it will generate the Character same as like ch[i] doing.

Random rnd = new Random();    // random class for random generate the numbers using .Next()

for (int i = 0; i <= 2; i++) // For loop
{
j = j + 1;      //increment the J variable for Random Characters.

// Create nums Array.
int[] nums = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

// create an characters Array for it.
char[] ch = new char[] { ‘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’ };

nums[i] = nums[rnd.Next(0, 9)];
ch[i] = ch[rnd.Next(0, 20)];
ch[j] = ch[rnd.Next(0, 25)];

pin_pwd += nums[i].ToString() + ch[i].ToString() + ch[j].ToString().ToUpper();
// just add/append the nums and ch in pin_pwd.
//pin_pwd will store the string of random generated password.

}

if (con.State == ConnectionState.Closed)
{
con.Open();
}

// following will check the random generated no. is exists in database or not if YES then //generate new one for it.

adp = new SqlDataAdapter(“select LOWER(password) AS password from tbl_name  where password=@password “, con);
adp.SelectCommand.Parameters.AddWithValue(“@password”, pin_pwd.ToLower());
dt = new DataTable();
adp.Fill(dt);
adp.Dispose();
if (dt.Rows.Count == 0)
{
return pin_pwd;
dt.Dispose();

// if not found then return it.
}
else
{

// if record exits then generate new one and return it.
for (int i = 0; i <= 2; i++)
{
j = j + 1;
int[] nums = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
char[] ch = new char[] { ‘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’ };
nums[i] = nums[rnd.Next(0, 9)];
ch[i] = ch[rnd.Next(0, 20)];
ch[j] = ch[rnd.Next(0, 25)];

pin_pwd += nums[i].ToString() + ch[i].ToString() + ch[j].ToString().ToUpper();
}
return pin_pwd;
dt.Dispose();
}
con.Close();
}

with regards
vik

OUTPUT:-

0tI1hE3gF

Posted in Asp.net

Joy of Helping

Any sort of help to the children who are fatherless, poor & are from far-off areas.
Joy of Helping

Facebook Link

Asp dot Net ,Ajax,Xml.

Recent Posts

  • ROW_NUMBER(), NTILE(), partition by, Duplicate Records, CTE sql server 2008
  • How to get second highest Salary sql server 2008
  • Insert values, insert into, insert default value, insert execute and select into sql server 2008
  • How to Bind GridView with SqlDataReader in Asp.net
  • how to attach files to email without storing on disk using Asp.net FileUpload control

Recent Comments

  • Anonymous on ROW_NUMBER(), NTILE(), partition by, Duplicate Records, CTE sql server 2008
  • dhananjay on How to use GridView with Insert, Edit, Update, Delete the Ado.net way C#
  • dev on How can we limit the characters in multiline textbox asp.net using JavaScript
  • navneet on How to display image in Image control after upload on the server asp.net C#
  • AnhVu on How to do Shopping Cart in Asp.net C#

Archives

  • February 2013
  • September 2012
  • April 2012
  • January 2012
  • October 2011
  • August 2011
  • May 2011
  • April 2011
  • March 2011

Categories

  • Asp.net
  • jQuery
  • Sql Server

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

EvoLve theme by Theme4Press  •  Powered by WordPress How to use Asp.net