public string UpdateLastLoginDB() { ClsDatabaseReader efactDB = new ClsDatabaseReader(); string queryStr = ""; queryStr = "UPDATE Users SET UserLastLoginDate = \"" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\" "; queryStr += "WHERE UserId = \"" + UserName + "\""; string returnStr = ""; efactDB.ExecuteDBCommand(queryStr, "ClsLoginUpdateLastLoginDB1"); queryStr = ""; queryStr = "INSERT INTO CurrentUsers ("; queryStr += "CurrentUserId, "; queryStr += "CurrentLastLoginDate) "; queryStr += "VALUES ("; queryStr += "\"" + UserName + "\", "; queryStr += "\"" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\") "; returnStr = ""; efactDB.ExecuteDBCommand(queryStr, "ClsLoginUpdateLastLoginDB2"); return(returnStr); }
public Boolean CheckUserLoggedIn() { Boolean IsUserLoggedIn = false; ClsDatabaseReader efactDB = new ClsDatabaseReader(); string queryStr = "SELECT * FROM CurrentUsers WHERE CurrentUserId = \"" + UserName + "\""; using (SqlDataReader dr = efactDB.ExecuteDBCommand(queryStr, "CLSLoginCheckUserLoggedIn")) { if (dr != null) { dr.Read(); if (dr.HasRows) // If any user found? { MessageBox.Show("User " + UserName + " is already logged in ", "Login Error", MessageBoxButton.OK, MessageBoxImage.Error); IsUserLoggedIn = true; } } } return(IsUserLoggedIn); }
public Boolean CheckUserExistInDB() { ClsDatabaseReader efactDB = new ClsDatabaseReader(); string queryStr = "SELECT * FROM Users WHERE UserId = \"" + UserName + "\""; Boolean IsUserExist = true; using (SqlDataReader dr = efactDB.ExecuteDBCommand(queryStr, "ClsLoginCheckUserExistInDB")) { if (dr != null) { dr.Read(); if (dr.HasRows) // If any user found? Yes, check for correct User name and password { if (dr["UserId"].ToString() != UserName || dr["UserPwd"].ToString() != Encrypt(UserPassword, UserName)) { MessageBox.Show("Username or Password is invalid", "User Login", MessageBoxButton.OK, MessageBoxImage.Error); NumberOfLogins += 1; IsUserExist = false; log.Write_SysLog(UserName, "LOGIN", "", "Invalid User login", 0); } else { if (dr["Userstatus"].ToString() == "D") { MessageBox.Show("User is disabled. Contact your Security Officer", "User Login", MessageBoxButton.OK, MessageBoxImage.Error); IsUserExist = false; log.Write_SysLog(UserName, "LOGIN", "", "User is disabled", 0); } else { UserName = dr["UserId"].ToString(); UserPassword = dr["UserPwd"].ToString(); UserLstLoginDate = (DateTime)dr["UserLastLoginDate"]; UserActivationDate = (DateTime)dr["UserActivationDate"]; UserPwdExpireDate = (DateTime)dr["UserPwdExpireDate"]; UserForcePwdChange = (Boolean)dr["UserForcePwdChange"]; UserProfileEndDate = (DateTime)dr["UserProfileEndDate"]; UserRecordStatus = dr["UserRecordStatus"].ToString(); } } } else { MessageBox.Show("Username or Password is invalid.", "User Login", MessageBoxButton.OK, MessageBoxImage.Error); NumberOfLogins += 1; IsUserExist = false; log.Write_SysLog(UserName, "LOGIN", "", "Invalid User login", 0); } } else { // Database error, something wrong with the tables. Can not read the table MessageBox.Show("Database pecific error", "User Login", MessageBoxButton.OK, MessageBoxImage.Error); IsUserExist = false; } } return(IsUserExist); }
public string UpdateLastLoginDB() { ClsDatabaseReader efactDB = new ClsDatabaseReader(); string queryStr = ""; queryStr = "UPDATE Users SET UserLastLoginDate = \"" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\" "; queryStr += "WHERE UserId = \"" + UserName + "\""; string returnStr = ""; efactDB.ExecuteDBCommand(queryStr, "ClsLoginUpdateLastLoginDB1"); queryStr = ""; queryStr = "INSERT INTO CurrentUsers ("; queryStr += "CurrentUserId, "; queryStr += "CurrentLastLoginDate) "; queryStr += "VALUES ("; queryStr += "\"" + UserName + "\", "; queryStr += "\"" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\") "; returnStr = ""; efactDB.ExecuteDBCommand(queryStr, "ClsLoginUpdateLastLoginDB2"); return returnStr; }
public Boolean CheckUserLoggedIn() { Boolean IsUserLoggedIn = false; ClsDatabaseReader efactDB = new ClsDatabaseReader(); string queryStr = "SELECT * FROM CurrentUsers WHERE CurrentUserId = \"" + UserName + "\""; using (SqlDataReader dr = efactDB.ExecuteDBCommand(queryStr, "CLSLoginCheckUserLoggedIn")) { if (dr != null) { dr.Read(); if (dr.HasRows) // If any user found? { MessageBox.Show("User " + UserName + " is already logged in ", "Login Error", MessageBoxButton.OK, MessageBoxImage.Error); IsUserLoggedIn = true; } } } return IsUserLoggedIn; }
public Boolean CheckUserExistInDB() { ClsDatabaseReader efactDB = new ClsDatabaseReader(); string queryStr = "SELECT * FROM Users WHERE UserId = \"" + UserName + "\""; Boolean IsUserExist = true; using (SqlDataReader dr = efactDB.ExecuteDBCommand(queryStr, "ClsLoginCheckUserExistInDB")) { if (dr != null) { dr.Read(); if (dr.HasRows) // If any user found? Yes, check for correct User name and password { if (dr["UserId"].ToString() != UserName || dr["UserPwd"].ToString() != Encrypt(UserPassword, UserName)) { MessageBox.Show("Username or Password is invalid", "User Login", MessageBoxButton.OK, MessageBoxImage.Error); NumberOfLogins += 1; IsUserExist = false; log.Write_SysLog(UserName, "LOGIN", "", "Invalid User login", 0); } else { if (dr["Userstatus"].ToString() == "D") { MessageBox.Show("User is disabled. Contact your Security Officer", "User Login", MessageBoxButton.OK, MessageBoxImage.Error); IsUserExist = false; log.Write_SysLog(UserName, "LOGIN", "", "User is disabled", 0); } else { UserName = dr["UserId"].ToString(); UserPassword = dr["UserPwd"].ToString(); UserLstLoginDate = (DateTime)dr["UserLastLoginDate"]; UserActivationDate = (DateTime)dr["UserActivationDate"]; UserPwdExpireDate = (DateTime)dr["UserPwdExpireDate"]; UserForcePwdChange = (Boolean)dr["UserForcePwdChange"]; UserProfileEndDate = (DateTime)dr["UserProfileEndDate"]; UserRecordStatus = dr["UserRecordStatus"].ToString(); } } } else { MessageBox.Show("Username or Password is invalid.", "User Login", MessageBoxButton.OK, MessageBoxImage.Error); NumberOfLogins += 1; IsUserExist = false; log.Write_SysLog(UserName, "LOGIN", "", "Invalid User login", 0); } } else { // Database error, something wrong with the tables. Can not read the table MessageBox.Show("Database pecific error", "User Login", MessageBoxButton.OK, MessageBoxImage.Error); IsUserExist = false; } } return IsUserExist; }