Advertisement
Guest User

daria

a guest
Jul 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. public bool ValidateUser(string Username, string Password)
  2.         {
  3.             bool result = false;
  4.  
  5.             Connection connectionString = new Connection();
  6.  
  7.             using (SqlConnection connection = new SqlConnection(connectionString.ConnectionString))
  8.             {
  9.                 using (SqlCommand command = new SqlCommand())
  10.                 {
  11.                     connection.Open();
  12.  
  13.                     command.Connection = connection;
  14.                     command.CommandType = CommandType.Text;
  15.                     command.CommandText = @"if exists (select EmployeeName, Password from Employee
  16.                                            where EmployeeName = @Name AND Password = @Password)
  17.                                            select 1;
  18.                                            else
  19.                                            select 0;";
  20.  
  21.                     command.Parameters.Add("@Name", SqlDbType.NVarChar, 50).Value = Username;
  22.                     command.Parameters.Add("@Password", SqlDbType.NVarChar, 8).Value = Password;
  23.  
  24.                     result = Convert.ToBoolean(command.ExecuteScalar());
  25.  
  26.                     connection.Close();
  27.                 }
  28.             }
  29.  
  30.             return result;
  31.         }
  32.  
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement