//Login Service Implmentation public AuthenticateReply authenticateUser(AuthenticateUser authUserData) { //Creating the instance of the Message Contract Typw which is required to send to the user AuthenticateReply authenticateReply = new AuthenticateReply(); authenticateReply.VoyageisAuthenticated = false; //creating the instance of the Conenction DbConnection connection = new DbConnection(); SqlConnection con = connection.connectToDatabase(); //Creating the instance of the Sql Command Object SqlCommand cmd = new SqlCommand(); cmd.Connection = con; //Parameterized query for the Database to authenticate the user cmd.CommandText = "Select Id,UserName,userPassword from VoyageUser where UserName=@username and userPassword=@password"; cmd.Parameters.AddWithValue("@username", authUserData.VoyageUserName); cmd.Parameters.AddWithValue("@password", authUserData.VoyagePassword); try { con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.Read()) { authenticateReply.VoyageisAuthenticated = true; authenticateReply.VoyageUserId = Int32.Parse(rdr["Id"].ToString()); rdr.Close(); } //rdr.Close(); } catch (Exception ex) { //creating the custom exception so that the client can be awared about the exception occured on the service side. Console.WriteLine("Error Message is:" + ex.Message); Custom_Exception exception = new Custom_Exception(); exception.Title = "Error Occured While authenticating the Voyage User"; exception.ExceptionMessage = ex.Message; throw new FaultException <Custom_Exception>(exception); } finally { //finally closing the Database Connection con.Close(); } return(authenticateReply); }
public int userAuthenticate([FromBody] AuthenticateUser user) { //Creating the instance of the Message Contract Typw which is required to send to the user AuthenticateReply authenticateReply = new AuthenticateReply(); authenticateReply.VoyageisAuthenticated = false; //creating the instance of the Conenction DbConnection connection = new DbConnection(); SqlConnection con = connection.connectToDatabase(); //Creating the instance of the Sql Command Object SqlCommand cmd = new SqlCommand(); cmd.Connection = con; //Parameterized query for the Database to authenticate the user cmd.CommandText = "Select Id,UserName,userPassword from VoyageUser where UserName=@username and userPassword=@password"; cmd.Parameters.AddWithValue("@username", user.username); cmd.Parameters.AddWithValue("@password", user.password); try { con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.Read()) { authenticateReply.VoyageisAuthenticated = true; authenticateReply.VoyageUserId = Int32.Parse(rdr["Id"].ToString()); rdr.Close(); } //rdr.Close(); } catch (Exception ex) { return(-99); } finally { //finally closing the Database Connection con.Close(); } return(authenticateReply.VoyageUserId); }