Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Data.SqlClient;
- namespace FormProject
- {
- public class Login
- {
- string sqlConnectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\Users\171296U\Desktop\Sensor-GroupProject\Database\Database.mdf;Integrated Security=True;Connect Timeout=30";
- bool isLoggedIn = false;
- public bool TryDoingLogin(string user, string password)
- {
- string sqlstatement = "Select Count(*) from [User] where Username=@user and Password=@pass";
- using (SqlConnection connection = new SqlConnection(sqlConnectionString))
- {
- using (SqlCommand command = new SqlCommand(sqlstatement, connection))
- {
- command.Parameters.AddWithValue("@user", user);
- command.Parameters.AddWithValue("@pass", password);
- connection.Open();
- SqlDataReader dr = command.ExecuteReader();
- if (dr.HasRows)
- {
- bool isLoggedIn = true;
- return true;
- }
- else
- {
- bool isLoggedIn = false;
- return false;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement