public static void Logout() { _account = null; }
// // Constructors // #region Constructors /// <summary> /// Initializes the members of this instance. /// </summary> static Globals() { _database = new SQLServerDatabase(@"Gamer-PC\SQLEXPRESS", "HCS"); _account = null; _kwh = 0; _microcontroller = null; /*bool flag = false; foreach (ConnectionStringSettings css in ConfigurationManager.ConnectionStrings) { try { _database = new SQLServerDatabase(css.ConnectionString); flag = true; break; } catch { } } if (!flag) throw new ArgumentException("No connection string was valid.");*/ }
// // Methods // #region Methods // // Accounts // #region Accounts public static async Task<bool> Login(string username, string password) { var salt = await _database.CallSPScalarAsync("Salt", "Accounts_GetSalt", new SqlParameter("@Username", SqlDbType.Char, 16) { Value = username.Trim().Truncate(16) }); if (salt == null) return false; var hashed = Hash.ComputeHash(password, Hash.Algorithms["SHA512"], System.Text.Encoding.UTF8.GetBytes(salt.ToString())); var table = await _database.CallSPReaderAsync("Account", "Accounts_Login", new SqlParameter("@Username", SqlDbType.Char, 16) { Value = username.Trim().Truncate(16) }, new SqlParameter("@Password", SqlDbType.Char, 96) { Value = hashed }); _account = new Account( (int)table.Rows[0]["AccountID"], table.Rows[0]["Username"].ToString().Trim(), table.Rows[0]["Password"].ToString().Trim(), table.Rows[0]["Salt"].ToString().Trim(), table.Rows[0]["AccountType"].ToString().Trim(), (bool)table.Rows[0]["Active"]); return (salt != null && hashed != null && table != null); //var hashed = Hash.ComputeHash(password, Hash.Algorithms["SHA512"], System.Text.Encoding.UTF8.GetBytes(salt.ToString())); //System.Threading.Thread.Sleep(1000); //return salt != null; }