login application in asp.net 3.5 using web service from sqlserver.

Posted by Dn2010 under ASP.NET on 3/12/2012 | Points: 10 | Views : 5622 | Status : [Member] | Replies : 3
hi friends,

how to login application in asp.net 3.5 using web service from sqlserver.


CREATE TABLE login(UserName varchar(200),Password varchar(64))


please give code for it.

thanks in advance.




Responses

Posted by: Sksamantaray on: 3/12/2012 [Member] Silver | Points: 25

Up
0
Down
Create a WebMethod in Service class with two parameters(username and password)
in the web method return a value for success login and trap it in your login page.
Then in the LoginPage on Login Button Click create an object of ServiceReference Class and using that object call your web method.

Thanks,
Sanjay

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vinay13mar on: 11/14/2012 [Member] Starter | Points: 25
Posted by: Prabu_Spark on: 11/16/2012 [Member] Starter | Points: 25

Up
0
Down
using System.Data;
using System.Data.SqlClient;

[Web method]

public bool authenticate_login(String username,String password)
{
SqlConnection con=new SqlConnection(@"Datasource=prabu;initial catalog=project;integrated security=true;username=hi;password=123");
SqlCommand cmd;
SqlDataAdapter sda=new SqlDataAdapter();
Datatable dt=new Datatable();
con.open();
cmd=new SqlCommand("select * from tbl_login",con);
sda.SelectCommand=cmd;
sda.fill(dt);
if(dt.rows.count>0)
return true;
else
return false;
con.close();
}


[Note: Add webreference of webservice to the application and give the reference name as localhost]

protected sub Button1_Click()
{
bool b;
localhost l1=new localhost();
b=l1.authenticate_login(txt_username.text,txt_pwd.text);
if(b=='true')
Response.redirect("Home.aspx");
else
Response.Write("Invalid login credentials");
}

With regards,
J.Prabu.
[Email:prbspark@gmail.com]

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response