How can Java programs authenticate passwords from the Linux passwd or shadow password files?

Nathan Meyers

There is no core capability in the JRE to use host authentication mechanisms, but you've got a couple of options:

  • Write some JNI code using the native methods used by Linux applications - getspnam() to retrieve the current current password entry (including the encrypted password), and crypt() to encrypt the supplied password for comparison.
  • Install the Java Authentication and Authorization Service (JAAS) extension, plus a JAAS authentication module that knows how to do Linux password authentication. Unfortunately, I don't know where to find such a module.