Exemplo n.º 1
0
        public static void Error(string Function = "", string Message = "")
        {
            try {
                string filename  = "log.err";
                string path      = GetPath(filename);
                string timestamp = DateTime.UtcNow.ToString("dd:MM:yyyy HH:mm:ss.fff", CultureInfo.InvariantCulture);

                string log = $"{Function}     -     {Message}\n---------------------------------------------------------------------------------------";
                using (StreamWriter sw = File.AppendText(path))
                    Write(timestamp, log, sw);
            }
            catch {
                CstmMsgBx.Error("Couldn´t write to log file");
                System.Threading.Thread.Sleep(5000);
                Application.Current.Shutdown();
            }
        }
Exemplo n.º 2
0
        public static (string salt, string password, string permissions) AuthenticateLogin(string Username)
        {
            try {
                string salt = "", password = "", permission = "", sql = "";
                int    IdUser = GetUserID(Username);

                ConnectOpen();
                sql = $"SELECT id, role FROM employee WHERE username = '******'";
                using (SQLiteCommand cmd = new SQLiteCommand(sql, CONNECTION)) {
                    SQLiteDataReader dataReader = cmd.ExecuteReader();
                    while (dataReader.Read())
                    {
                        permission = dataReader["role"].ToString();
                    }
                }

                sql = $"SELECT salt, password FROM employee_login WHERE id_user = '******'";
                using (SQLiteCommand cmd = new SQLiteCommand(sql, CONNECTION)) {
                    SQLiteDataReader dataReader = cmd.ExecuteReader();
                    while (dataReader.Read())
                    {
                        salt     = dataReader["salt"].ToString();
                        password = dataReader["password"].ToString();
                    }
                }
                ConnectClose();

                return(salt, password, permission);
            }
            catch (Exception exc) {
                CstmMsgBx.Error("A error occurred while trying to authenticate username and password");
                Log.Error(Log.GetMethodName(), exc.ToString());
                CheckConnectionStatus();
                return(null, null, null);
            }
        }