views:

25

answers:

1

Hello everyone,

I am hoping someone can help me this this problem.

I know how to password protect a page in wordpress admin area, in the edit page area, edit the visibility and set it to password protected. I want to know if there are wordpress php functions to check if the user typed in the correct password in the layout php file. It seems to only show the password input box if is in your layout. I am showing alot more content than just from the wordpress post in my layout. I want to be able to check if the user has already typed in this password and then show the rest of this content.

Now as I was writing this, I thought up one idea, it doesnt use any wordpress functions. I could potentially check the cookie that wordpress sets for this, just check if the cookie exists and then we know the person is logged in. This is assuming that the password protected pages use cookies.

Any help on this is appreciated.

Thanks, Ian

A: 

You should check the sessions rather than the cookies. It seems unlikely that Wordpress would check your login status in a cookie since they are so easy to fake. It might check for an encrypted password in the cookies and log in using that, and then create a session.

vichle
Actually it is stored as a cookie, the password is stored in plain text as well. The cookie is keyed like this: wordpress_cjdfh4ruj49032nn8934n23456n3498i4n. I have no idea what the random string after wordpress_ is, some hashed value probably. So assuming this stays the same, just look at the cookie array with that array key and make sure the value is the same value that was set in wordpress admin. If the cookie key changes, we would have to loop through the cookie array searching for a key that begins with wordress_ and has the correct password. This is how I did it and it works great.
Ian
Oh, so no more wordpress ever again then... Good to know.
vichle