generating alpha numeric password using stored procedure

 
CREATE PROC random_password
(
@len int = 8, --Length of the password to be generated
@password_type char(7) = 'simple' 
--Default is to generate a simple password with lowecase letters. 
--Pass anything other than 'simple' to generate a complex password. 
--The complex password includes numbers, special characters, upper case and lower case letters
)
AS
/*************************************************************************************************
               Copyright © 2001 Narayana Vyas Kondreddi. All rights reserved.
                                          
Purpose:       To generate a random password
 
Written by:    Narayana Vyas Kondreddi
               http://vyaskn.tripod.com
 
Tested on:     SQL Server 7.0 and SQL Server 2000
 
Date modified: March-29-2001 01:15 PM
 
Email:         vyaskn@hotmail.com
 
Examples:
 
To generate a simple password with a length of 8 characters:
EXEC random_password
 
To generate a simple password with 6 characters:
EXEC random_password 6
 
To generate a complex password with 8 characters:
EXEC random_password @Password_type = 'complex'
 
To generate a comples password with 6 characters:
EXEC random_password 6, 'complex'
*************************************************************************************************/
BEGIN
DECLARE @password varchar(25), @type tinyint, @bitmap char(6)
SET @password='' 
SET @bitmap = 'uaeioy' 
--@bitmap contains all the vowels, which are a, e, i, o, u and y. These vowels are used to generate slightly readable/rememberable simple passwords
 
WHILE @len > 0
BEGIN
        IF @password_type = 'simple' --Generating a simple password
        BEGIN
        IF (@len%2) = 0  --Appending a random vowel to @password
               
               SET @password = @password + SUBSTRING(@bitmap,CONVERT(int,ROUND(1 + (RAND() * (5)),0)),1)
        ELSE --Appending a random alphabet
               SET @password = @password + CHAR(ROUND(97 + (RAND() * (25)),0))
               
        END
        ELSE --Generating a complex password
        BEGIN
               SET @type = ROUND(1 + (RAND() * (3)),0)
 
               IF @type = 1 --Appending a random lower case alphabet to @password
                       SET @password = @password + CHAR(ROUND(97 + (RAND() * (25)),0))
               ELSE IF @type = 2 --Appending a random upper case alphabet to @password
                       SET @password = @password + CHAR(ROUND(65 + (RAND() * (25)),0))
               ELSE IF @type = 3 --Appending a random number between 0 and 9 to @password
                       SET @password = @password + CHAR(ROUND(48 + (RAND() * (9)),0))
               ELSE IF @type = 4 --Appending a random special character to @password
                       SET @password = @password + CHAR(ROUND(33 + (RAND() * (13)),0))
        END
 
        SET @len = @len - 1
END
 
SELECT @password --Here's the result
 
END
 
 

 

Leave a Comment

stored procedure for creating a random password in sql

CREATE PROC random_password
(
@len int = 8, --Length of the password to be generated
@password_type char(7) = 'simple' 
--Default is to generate a simple password with lowecase letters. 
--Pass anything other than 'simple' to generate a complex password. 
--The complex password includes numbers, special characters, upper case and lower case letters
)
AS

Leave a Comment

How many users are using a site at a same time?

 

When a site runs then how we can find that in a single time, how many users are using the site? In this article I am going to show how we can trap that how many users are hitting the site.


For this I used Global.asax. In Global.asax we find many method such as 

Application_Start, Application_End, Session_Start, Session_End etc.

I used here Application_Start and Session_Start method.

In Application_Start method I declare a varaible of Aplication Type like as:

 

void Application_Start(object sender, EventArgs e)

{

    Application["User"] = 0;

}

After declaring it, I used Session_Start Method like as:

void Session_Start(object sender, EventArgs e)

{

    int count;

    count = (int)Application["User"];

    count = count + 1;

    Application["User"]=count;

}

In this Session_Start method I declare a variable of integer type. I type cast the Application["User"] with int to store the value of Application["User"]  in variable count. On running application a new session create. So when new session will create then this Session_start method will call. On every call the value of variable count will increase by 1. With this we can trap the total no. of users, which are hitting the site at a same time.

The number of total users will come on form. For this I do the code on Page_Load like as:

protected
void Page_Load(object sender, EventArgs e)
{
    Response.Write(Application[
"User"].ToString());
}
 

 

Leave a Comment

ajax tuitorials

Leave a Comment

retrieving password using forgot password control

in  the  web  config  we  have  to  write

<system.net><mailSettings><smtp deliveryMethod=Network from=bineetha@sprint.co.in ><network host=192.168.1.83 defaultCredentials=true port=25/></smtp>and  inside  the  control

<asp:PasswordRecovery ID=”PasswordRecovery1″ runat=”server”> <MailDefinition IsBodyHtml=”True” Priority=”High” Subject=”Your password” BodyFileName=”~/HtmlBody.txt”>in  the  html.txt file  we  have  to  specify  the  model  of  email  to  be  received

</MailDefinition><InstructionTextStyle Font-Italic=”True” ForeColor=”Black” />

<SuccessTextStyle Font-Bold=”True” ForeColor=”#5D7B9D” /><TextBoxStyle Font-Size=”0.8em” />

<TitleTextStyle BackColor=”#5D7B9D” Font-Bold=”True” Font-Size=”0.9em” ForeColor=”White” /><SubmitButtonStyle BackColor=”#FFFBFF” BorderColor=”#CCCCCC” BorderStyle=”Solid” BorderWidth=”1px”

Font-Names=”Verdana” Font-Size=”0.8em” ForeColor=”#284775″ /> </asp:PasswordRecovery></mailSettings></system.net>

Leave a Comment

common errors

“Invalid postback or callback argument. 

Event validation is enabled using <pages enableEventValidation=”true”/> in configuration or

<%@ Page EnableEventValidation=”true” %> in a page. 

For security purposes, this feature verifies that arguments to postback or callback events

originate from the server control that originally rendered them.  If the data is valid

and expected, use the ClientScriptManager.RegisterForEventValidation method in order to

register the postback or callback data for validation.”
Answer :
——–

# re: EnableEventValidation error on button postback using a multipart form in .NET v2.0 I had a similiar problem. I fixed it by putting my databinding code in the Page_Load event in a !Page.IsPostBack block. I got the solution here:

2]Invalid attempt to read when no data is present
answer
——–

reader  obj should  use  as  shown  below

sqlReader = sqlCmd.ExecuteReader();
sqlReader.Read();

txtBkNum_brw.Text = sqlReader["BookNumber"].ToString();
txtBookTtl_brw.Text = sqlReader["BookTitle"].ToString();
txtAuth_brw.Text = sqlReader["Author"].ToString();
comboBox1.Text = sqlReader["Category"].ToString();

sqlReader.Close();

Leave a Comment

uploading an image

using  file  upload  control  we  can  do  that 

after  that  we  should  save  the  filename  of  the  image  in  our  database 

string imagestring = Path.GetFileName(fileimg.PostedFile.FileName);for  this  we  have  to  import  a  namespace

using System.IO;string a = Path.GetFileName(photofile.PostedFile.FileName);

            if (a != “”)
            {
                string filetype = photofile.PostedFile.ContentType;
                int filelength = photofile.PostedFile.ContentLength;
               // Response.Write(filelength.ToString());
                if (filelength <= 1048567)
                {
                    if (filetype == “image/pjpeg” || filetype == “image/jpg” || filetype == “image/gif”)
                    {
                        photofile.PostedFile.SaveAs(Server.MapPath(“.”).ToString() + @”\image\” + a);

}

}

}

Leave a Comment

binding data in a drpdown

SqlCommand cmd1 = new SqlCommand(selstr1, Con()); SqlDataAdapter ada = new SqlDataAdapter(cmd1); DataSet ds = new DataSet();ada.Fill(ds);

ddlProductCategory.DataSource = ds.Tables[0];

ddlProductCategory.DataTextField = “CategoryName”;ddlProductCategory.DataValueField = “CategoryId”;ddlProductCategory.DataBind();

Leave a Comment

maintaing a cart

 we  have  to  make  a  datatable  like  this 

public object makeCart(){

objDT = new System.Data.DataTable(“Cart”);objDT.Columns.Add(“ID”, typeof(int));objDT.Columns[

"ID"].AutoIncrement = true;objDT.Columns["ID"].AutoIncrementSeed = 1;objDT.Columns.Add(

“Quantity”, typeof(int));objDT.Columns.Add(“Product”, typeof(string));objDT.Columns.Add(

“Cost”, typeof(decimal));return objDT;}

in  the  page  load

if (Session["Cart"]==null){

Session["Cart"] = makeCart();}

then  in  the  add  to  cart  button  click 

protected void btnAddtocart_Click(object sender, EventArgs e){

objDT = (DataTable)Session["Cart"];object Product = lblName.Text;

bool blnMatch = false; foreach (DataRow objDR in objDT.Rows){

if (objDR["Product"].Equals(Product)){

objDR["Quantity"] = (object)(Convert.ToInt32(objDR["Quantity"]) + Convert.ToInt32(txtQty.Text));blnMatch = true;

break;}

}

if (!blnMatch){

objDR = objDT.NewRow();

objDR["Quantity"] = Int32.Parse(txtQty.Text);objDR["Product"] = lblName.Text;objDR[

"Cost"] = decimal.Parse(lblPrice.Text);objDT.Rows.Add(objDR);

}

Session["Cart"] = objDT;Response.Redirect(“viewcart.aspx”);}

 then  in  the  view  cart  page

protected void Page_Load(object sender, EventArgs e){

if (!IsPostBack){

cart = (DataTable)Session["Cart"];girdCart.DataSource = cart;

girdCart.DataBind();

if (Session["Cart"] != null){

total = GetItemTotal();

lblDispalyTot.Text = “Total: $” + total.ToString();}

}

}

protected void btnContunueShopping_Click(object sender, EventArgs e){

Response.Redirect(“Home.aspx”);}

protected void girdCart_RowDeleting(object sender, GridViewDeleteEventArgs e){

cart = (DataTable)Session["Cart"];cart.Rows[e.RowIndex].Delete();

girdCart.DataSource = cart;

girdCart.DataBind();

total = GetItemTotal();

lblDispalyTot.Text = “Total: $” + total.ToString();if (cart.Rows.Count == 0){

btnEmptyCart_Click(sender,e);

}

}

public decimal GetItemTotal(){

for (intCounter = 0; intCounter <= cart.Rows.Count – 1; intCounter++){

objDR = cart.Rows[intCounter];

decRunningTotals += (decimal)(Convert.ToInt32(objDR["Cost"]) * Convert.ToInt32(objDR["Quantity"]));}

return decRunningTotals;}

protected void btnCheckout_Click(object sender, EventArgs e){

Response.Redirect(“~/SignIn.aspx”);}

protected void girdCart_RowUpdating(object sender, GridViewUpdateEventArgs e){

string quantity;cart = (DataTable)Session["Cart"];objDR = cart.Rows[e.RowIndex];

quantity = ((TextBox)girdCart.Rows[e.RowIndex].Cells[1].FindControl(“txtqty”)).Text;objDR[

"Quantity"] = Convert.ToInt32(quantity);girdCart.DataSource = cart;

girdCart.DataBind();

total = GetItemTotal();

lblDispalyTot.Text = “Total: $” + total.ToString();}

protected void btnEmptyCart_Click(object sender, EventArgs e){

Session["Cart"] = null;cart =(DataTable) Session["Cart"];girdCart.DataSource = cart;

girdCart.DataBind();

lblDispalyTot.Text = ” “;lblCart.Text = “Your Cart is empty now”;}

Leave a Comment

customised forms authentication

in  customised  forms  authentication   we  can  use  our  database  and  with  login  controls

the  webconfig  settings  for  that  is  given  below

<connectionStrings><add name=dbstring connectionString=Data Source=AST020\sqlexpress;Initial Catalog=simpleshoppingcart;uid=sa;pwd=assyst;/></connectionStrings><system.web><

membership defaultProvider=CustomizedProvider><providers><add connectionStringName=dbstring applicationName=simpleshoppingcart minRequiredPasswordLength=5 minRequiredNonalphanumericCharacters=0 name=CustomizedProvider type=Membership/></providers></

membership><roleManager enabled=true defaultProvider=CustomizedRoleProvider><providers><add name=CustomizedRoleProvider type=role connectionStringName=dbstring/></

providers></roleManager><authentication mode=Forms><forms loginUrl=SignIn.aspx defaultUrl=SignIn.aspx name=RoleBasedFormAuthentication.ASPXAUTH/></

authentication><authorization>< allow users=?/></authorization>after  that  we can   restrict  the  memberes  according  to  their  roles

<authentication mode=Forms><forms loginUrl=default.aspx defaultUrl=default.aspx name=.ASPX_AUTH_COOKIE/></authentication><authorization><

deny users=?/></authorization><location path=Admin><system.web><

authorization><deny roles=manager/><deny roles=SWE/><allow roles=Admin/></

authorization></system.web></location><location path=SWE><

system.web><authorization><allow roles=manager/><allow roles=SWE/><

allow roles=Admin/></authorization></system.web></location><

location path=manager><system.web><authorization><allow roles=manager/><

deny roles=SWE/><deny roles=Admin/></authorization></system.web></

location></configuration>we  cam  implement  and  use  membership  provider  class

roleprovider  class

Leave a Comment

Older Posts »
Follow

Get every new post delivered to your Inbox.