I have a WebService with the following Method:
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
[WebMethod]
public string Login(string passwort, string email, string firma)
{
return LoginHelper.Login(passwort, email, firma);
}
My LoginHelper code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
namespace WebService1
{
public class LoginHelper
{
public static string Login(string passwort, string email, string firma)
{
string userName = "";
SqlConnection con = new SqlConnection(@"Data Source=Yeah-PC\SQLEXPRESS;Initial Catalog=works;Integrated Security=true;");
SqlCommand cmd = new SqlCommand(@"SELECT firma FROM TestData
WHERE email = @email", con);
cmd.Parameters.AddWithValue("@email", email);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
//userName += dr["email"].ToString();
//userName += dr["passwort"].ToString();
userName += dr["firma"].ToString();
}
dr.Close();
con.Close();
return userName;
}
}
}
Thanks for that help Guys
I have edited my Questions. Is that solution secure now? I mean against SQL-Injection. Is there something more what i can do better?
you are calling
LoginHelper.Login(passwort, email, firma);but in your method
public static string Login(string email, string passwort, string firma)email is fist parameter.
actually in email parameter you have password, that’s why it not return any result
change your
loginmethod inLoginHelperas below