21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Verifying a password encrypted using PBKDF2 works the same way as verifying a<br />

password encrypted with crypt( ): encrypt the plaintext password with the already<br />

encrypted password as the salt, and compare the result with the already encrypted<br />

password. If they match, the password is correct.<br />

For the sake of both consistency and convenience, you can use the following function,<br />

spc_pbkdf2_verify( ), to verify a password encrypted using PBKDF2.<br />

int spc_pbkdf2_verify(const char *plain_password, const char *crypt_password) {<br />

int match = 0;<br />

char *pbkdf2_result;<br />

if ((pbkdf2_result = spc_pbkdf2_encrypt(plain_password, crypt_password)) != 0) {<br />

match = !strcmp(pbkdf2_result, crypt_password);<br />

free(pbkdf2_result);<br />

}<br />

return match;<br />

}<br />

See Also<br />

Recipes 4.10, 8.9, 8.10<br />

8.12 Authenticating with PAM<br />

<strong>Problem</strong><br />

You need to perform authentication in your application, but you do not want to tie<br />

your application to any specific authentication system. Instead, you want to allow<br />

the system administrator to configure an authentication system that is appropriate<br />

for the environment in which the application will run.<br />

Solution<br />

Use Pluggable Authentication Modules (PAM), which provides an API that is independent<br />

of the underlying authentication system. PAM allows the system administrator<br />

to configure the authentication system or systems to use, and it supports a wide<br />

variety of existing systems, such as traditional Unix password-based authentication,<br />

Kerberos, Radius, and many others.<br />

Discussion<br />

We do not discuss building your own PAM modules in this book, but<br />

there is a recipe on that topic on the book’s web site.<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.<br />

Authenticating with PAM | 411

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!