If you are generating a hash salt, I presume you are storing it in some way? The first code makes no use of a salt. What you need to do is SELECT the password and the salt (or if its hardcoded than provide the variable within it), and then use an if check with it:
if (strcmp(generateHash($password, $salt), $storedpassword) == 0)
Where $password is the plain text provided password, $salt is the generated salt either stored as a variable configuration or within the database is fine, and $storedpassword is retrieved from the database based on the username.
If the salt is stored in the database unique to each record entry (or even on a joinable config table), than you can do it all in a query:
SELECT * FROM users WHERE username = '$userName' AND password = CONCAT(dbsalt, SHA1(dbsalt, $password))
Personally I'd use PHP for this, as it is a little bit more flexible when it comes to swapping algorithms.