2

What do I need to add, if I need to at all, to avoid sql injections?

public static Login GetLoginByName(string name)
{
    var context=new telephonyEntities1();

    Login t = (from l in context.Logins
               where l.login1==name
               select l).FirstOrDefault();
    return t;
}
the_drow
  • 18,571
  • 25
  • 126
  • 193
Yuriy Vikulov
  • 2,469
  • 5
  • 25
  • 32

1 Answers1

6

Linq-to-sql uses SqlParameter to generate SQL queries, so no you do not need to do anything extra.

From Frequently Asked Questions (LINQ to SQL)

Q. How is LINQ to SQL protected from SQL-injection attacks?

A. SQL injection has been a significant risk for traditional SQL queries formed by concatenating user input. LINQ to SQL avoids such injection by using SqlParameter in queries. User input is turned into parameter values. This approach prevents malicious commands from being used from customer input.

jeroenh
  • 26,362
  • 10
  • 73
  • 104