Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Services;
- using System.Web.Services.Protocols;
- using System.Xml.Linq;
- using System.Data.SqlClient;
- namespace LoginDetails
- {
- /// <summary>
- /// Summary description for Service1
- /// </summary>
- [WebService(Namespace = "http://tempuri.org/")]
- [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
- [ToolboxItem(false)]
- // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
- // [System.Web.Script.Services.ScriptService]
- public class Service1 : System.Web.Services.WebService
- {
- [WebMethod]
- public String GetLoginDetails(string UserName, string Password)
- {
- try
- {
- using (SqlConnection myConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=student;User ID=sa;Password=1234"))
- {
- myConnection.Open();
- using (SqlCommand myCommand = new SqlCommand())
- {
- myCommand.Connection = myConnection;
- myCommand.CommandText = "SELECT COUNT(*) FROM Login WHERE UserName = @UserName AND Password = @Password";
- myCommand.Parameters.Add("@UserName", SqlDbType.VarChar).Value = UserName;
- myCommand.Parameters.Add("@Password", SqlDbType.VarChar).Value = Password;
- return (int)myCommand.ExecuteScalar() == 1 ? "success" : "bad username or password";
- }
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- return "an error occurred.";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement