Migrating sha1 user passwords into drupal 7
You can use the Migrate framework and easily import accounts into Drupal 7 and it will take care of this for you. Don't bother with separate tables and password lookups and all that.

https://www.drupal.org/project/migrate

https://www.jeffgeerling.com/blogs/jeff-geerling/migrating-drupal-7-users-site

I can't find an actual example of a class that handles users into Drupal 7,
but the Migrate docs are very thorough.

Edit - here is an example: https://cgit.drupalcode.org/migrate/tree/migrate_example/beer.inc#n212

But in your case you will want to define another database connection in settings.php and define that as the source of the migration.