Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using DAL.Model;
- using System;
- using System.Collections.Generic;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Forms;
- namespace DAL
- {
- public class LecLogin
- {
- public async Task<LoginInfo> lLogin(String username, String password)
- {
- String queryString =
- "SELECT [Username] ,[Password] FROM [POETask2].[dbo].[tblLecturerSec] WHERE (Username = @user) and (Password = @pass)";
- String connectionString = DBConnector.getDBCon();
- String user = "";
- using (SqlConnection connection = new SqlConnection(connectionString))
- {
- SqlCommand cmd = new SqlCommand(queryString, connection);
- cmd.Parameters.AddWithValue("@user", username);
- cmd.Parameters.AddWithValue("@pass", password);
- connection.Open();
- SqlDataReader sqlReader = cmd.ExecuteReader();
- try
- {
- while (sqlReader.Read())
- {
- user = (String.Format("{0}, {1}",
- sqlReader["username"], sqlReader["password"])); // etc
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- finally
- {
- sqlReader.Close(); //Closing the reader
- }
- }
- if (user == "" || password == "")
- {
- MessageBox.Show("A username or password is required to login or you have entered the incorrect details!");
- return new LoginInfo { isSuccess = false };
- }
- else
- {
- MessageBox.Show(username + " has successfully signed in!", "Success!");
- return new LoginInfo { isSuccess = true, Username = user };
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement