Specific Use of external database system in user authentication

I have a wordpress site and I have a database system with thousands of users with name, password and email.

I would like that only people registered in this database be allowed to access the wordpress pages and comment on it, but I don't want to have to synchronize the wordpress users database with my database system.

I think the solution would be to have a custom login process for the wordpress site, where I just check in my database system if userid and password are fine, and if it is ok, set the wordpress comment cookie so that user can comment on the pages with their name and email, and the pages are not displayed if the comment cookie is not there.

Although I have been through the codex, I cannot figure out how to do this.
Your help will be really appreciated.