Monday, 18 March 2013

Login using Stored Procedure

-->


First create one table named Emp_Login in the SQL database which looks as in the following image:

Insert the One Record in the table as:
Insert into Emp_Login (userName,Password) values ('abcd2013','abcdefgh')
 
In the above table the usename column is used to store the User Name and Password is for the user's Password.
 
Now let us create a Stored Procedure named Emplogin as follows:
 

Create  procedure Emplogin
(
@Usename Varchar (20),
@Password varchar (10)
)
as
Begin
Select COUNT(*)from Emp_Login where username=@Usename and password=@Password 
End
 

In the above Stored Procedure named Emplogin the variable @Usename is used for the username and @Password is used for the password. The select query that I have written in the beginning counts the number of users from the table whose name matches with the exact two variables; that is @Usename and @Password which comes from the front end user input page.
 
Now create the project named Loginapplication or you can specify any name as:
  1. "Start" - "All Programs" - "Microsoft Visual Studio 2008/2010".
  2. "File" - "New Project" - "C#" - "Empty Project" (to avoid adding a master page).
  3. Give the web site a name such as Login or another as you wish and specify the location.
  4. Then right-click on Solution Explorer - "Add New Item" - Signin.aspx page for Login Credential and Welcome.aspx for redirecting after successful login.
  5. Drag and drop two buttons, one Label and two textBoxes on the <form> section of the Default aspx page.
Then the  <form> section of the Default aspx page looks as in the following:
 
Default page.png
 
Then double-click on btn2 and write the following code in the Button_click function as:
 

 protected void Button2_Click (objectsender, EventArgs e)
 {
     connection();
     query = "Emplogin";   //stored procedure Name
     SqlCommand com = new  SqlCommand(query, con);

     com.CommandType= CommandType.StoredProcedure;

     com.Parameters.AddWithValue("@Usename", TextBox1.Text.ToString());   //for username 
     com.Parameters.AddWithValue("@Password", TextBox2.Text.ToString());  //for password
     int usercount = (Int32)com.ExecuteScalar();// for taking single value
     if (usercount == 1)  // comparing users from table 
     {
         Response.Redirect("Welcome.aspx");  //for sucsseful login
     }
     else
     {
         con.Close();
         Label1.Text = "Invalid User Name or Password";  //for invalid login
     }
}
The most important part of the preceding code is the If condition part, I have used the one integer variable user count which is used to count the single value from the Stored Procedure using ExecuteScalar, if the records are found in the table it returns 1 then the page is redirected to the Welcome page otherwise it gives Invalid user Name or Password. 
 Which we are already entered into the table at the creation of the table.




Saturday, 2 March 2013

Search Now Learn Now

-->


LEARN NOW- SEO SEARCH ENGINE OPTIMIZATION (click on Image)

ASP.NET Tutorials For WEB Delopers (Click on Image)


JavaScript Tutorials
Microsoft SQL Server

Lesson 15

Learnt how to optimize keywords, title, alt, meta tags, anchor and other text from SEO point of view.
So in brief ethical strategies for achieving optimal ranking in the search engines are:
  • All Pages Must Conform with W3C Standards
  • Keyword Density is Never Abusive
  • Always Include: Robots.txt, Sitemap.xml, & Urllist.txt
  • Keywords are Prominent in the Title, META tags, & Headings
  • ALT Tags and Title Tags are Not Forgotten
  • Nomenclature is Fundamental to Being Indexed
 Keep visiting to us, Happy Learning!