The best thing to do here would be to have a stored procedure on your database. This way you will also never be exposing the password on the client-side.
To create the stored procedure on your server, try something like this:
CREATE PROCEDURE AuthenticateUser
(@username VarChar(25),
@password VarChar(25)) AS
SELECT
COUNT(*)
FROM COMPANY
WHERE Login = @username
AND Password = @password
RETURN @@Rowcount
And the code to access this stored procedure would be along the lines of:
//Open a connection to the database using your connection string
using (SqlConnection con = new SqlConnection("My Configuration string"))
{
//Open the connection
con.Open();
//Create a new command for the stored proc, using the existing connection just opened
using(SqlCommand cmd = new SqlCommand("AuthenticateUser", con))
{
cmd.CommandType = CommandType.StoredProcedure;
//Add the username and password to the command, as paramaters (Prevents a lot of security issues, such as SQL Injection)
cmd.Parameters.Add("@username", SqlDbType.VarChar, 25).Value = UserIdTextBox.Text;
cmd.Parameters.Add("@password", SqlDbType.VarChar, 25).Value = "Password";
//A paramater for the return value, which will be a bool (Only 0 or 1 should be returned from the database/stored proc)
SqlParameter ret = new SqlParameter("ret", SqlDbType.Int);
ret.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(ret);
//Execute the query
cmd.ExecuteNonQuery();
if (Convert.ToBoolean(ret.Value) == true)
{
//Login Successful
}
else
{
//Login Failed
}
}
}
The SQLParamaters help reduce the amount of interaction users can have with your database, as it sanitises the input instead of blindly accepting anything they input (Which could lead to them deleting your entire database).
But bear in mind. You should also hash and salt passwords. If you want to look at this, there's a question about it already on stack overflow. And it's very bad practice not to do this.