Password Protect

It would be great to implement some form of Password Protect for albums or entire directory, not using .htaccess. A guy just released something of interest for Wordpress that is similar to what I am thinking of. http://broome.us/archives/2007/01/31/the-wordpress-password-plugin/

Regards...
«1

Comments

  • I was just thinking about starting my own thread for this. I second this idea.

    I would like to have albums I can share with say family members only who have a password.
  • pennylessz28-

    I have the same situation as you, there are albums I would only like family to view.
  • If you don't need a 100% safe way of keeping others away from your family pics, it's rather easy to add a password to your theme. Simply use cookies in your album.php. If a cookies isn't set, show a form where you ask for the password. If the visitor has provided the correct password, you can set the cookie and send the code for generating the thumbnails.

    This is an album without a password:

    http://www.newwws.be/zenphoto/mieren

    And this is an album with a password:

    http://www.newwws.be/zenphoto/test (the password is zen)

    I work with a theme that uses a configuration file for each album. In that configuration file I can select whether to use a password or not. The cookie is valid for 30 minutes. After that time people will have to re-enter the password again. If you want to see the form in action again and don't want to wait 30 minutes, you can change the toplevel domain of the links into .org / .net / .tv / .us / .co.uk / .be

    groeten, Miriam
  • Miriam-

    If it's not too much trouble, you should share your work with the forum here? It might benefit others, if it's something you can package up easily. I'd be happy to write up the wiki article and place it in the ZenphotoHacks portion of the wiki. There have been a number of people (especially in this thread) asking about something like this. I know that this is planned for eventual release in the core zenphoto code, but this might help "hold" people over until that feature is integrated in the code.
  • I'll give it a try. I had to change the code a bit because I don't think that I have the time to explain here how the newwws-theme works with its own configuration files. I also made the way the cookies are written a bit easier to understand for those people who have never used cookies before.

    FIRST...

    Place this PHP code BEFORE the line with <!DOCTYPE etc....> in album.php

    `

    <?php<br />
    #========================[Private album]===========================

    /* $newwws_password is set in the album specific configuration file, but */

    /* if the name of an album starts starts with an underscore, we consider it to be */

    /* a private album too. The default-password will be zen */

    if (substr(getAlbumTitle(), 0, 1) == "_" && empty($newwws_password)) $newwws_password = "zen";

    /* Check if this is a private album and ask for a password */

    $newwws_passwordfile = $themepath . "/" . $theme . "/" . "newwws_password.php";

    if (empty($newwws_password)){

    $newwws_askforpassword = false;

    } else {

    $newwws_askforpassword = true;

    }

    $newwws_password_soll = $newwws_password;

    $newwws_password_ist = $_POST['newwws_pw'];

    if($_COOKIE["newwws_".strtolower(str_replace(" ", "_", getAlbumTitle()))] == "OK") $newwws_password_ist = $newwws_password_soll;

    if ($newwws_password_ist == $newwws_password_soll) {

    $newwws_askforpassword = false;

    setcookie ("newwws_".strtolower(str_replace(" ", "_", getAlbumTitle())),"OK",time()+1800, "/");

    }

    ?>

    `

    SECOND...

    Place this code in a new PHP-file called newwws_password.php in the same folder as album.php

    `

    ">









    `

    THIRD...

    Look in album.php for the line with the code for the thumbnails and replace it with this code. I've placed that code in a new php-file. With an include I can add that php-file to album.php:

    `

    <?php <br />
    if ($newwws_askforpassword){

    include("$newwws_passwordfile");

    } else {

    /* place the original thumbs generating code here */

    /* or include another php-file with the thumbs-code */

    include("$newwws_thumbs_php");

    }

    ?>

    `

    FOURTH...
    Enhance this - I'm not a programmer ;)

    I hope this helps.

    Groeten, Miriam
  • Excellent Miriam-

    Thanks! Maybe those who had the request out there for this can give it a try and see how it works for them. Meantime, as I get a chance I'll post it to the wiki.
  • seems to work just fine miriam on my dev site. here: http://www.thinkdreams.com/devzen/index.php?album=_cayman1996

    password is defaulted to "zen".

    i'll put this up on the wiki for reference.
  • Thanks @miriam and @thinkdreams. This has been a long standing request of Zenphoto users including me. One question though: Does this mean all albums will have the same password?
  • @Jayray999

    Based on what I see in the code: yes.

    Might be able to be tweaked a little, but I think that's what Miriam meant by Item #4: "Enhance this - I'm not a programmer"

    :)
  • @thinkdreams. Thanks for the reply.

    @miriam. Is the newwws-theme that you use publicly available. You say that, "I work with a theme that uses a configuration file for each album." Maybe that enables you to set a unique password for each album. If so, please do add the theme to @thinkdreams growing collection of ZP themes. Thanks again and incidentally, you have a wonderful site.
  • Cool. I just came to check out the support forums and saw these excellent replies.
    Thanks much for your insight! As soon as I am able I am going to test this out and will let you know how it goes.

    Will be interesting to see if I can get this to work along with Zenpress plugin to link photo in a post to an album.
  • jayray999w wrote: "One question though: Does this mean all albums will have the same password?"

    No, but you'll have to find yourself a way to set the variable $newwws_password to a unique value for every album. If $newwws_password is not empty, the user will be asked to enter the password stored in $newwws_password.

    I adapted the code a bit so a default password will be asked for every album with a name that starts with an underscore.

    The newwws theme is highly configurable. Without a configuration file it will show 18 thumbnails in 3 rows of 6 thumbnails and on a default background. With the configuration file you can change the number of thumbnails on each row, let's say 6-4-2 or 5-4-3. It's also possible to use a different background for every page in an album and by selecting another css and/or another script it is possible to change the way the thumbnails look.

    Despite it is easy to work with the configuration files, it is also possible to work without. In that case the theme will use the default settings.

    The newwws theme is far from ready and it will take some time before I will make it available to other people.

    Groeten, Miriam
  • @miriam. Thanks. Look forward to your eventual release.
  • I am working on a zenphoto plugin that will allow you to create a password protected album from within the admin section. You'll be able to select whether an album is password protected and if so set a password.

    I can't promise that it will be future compatible, but I will try my best to abstract as much of the code as possible which should help to make it compatible for future versions.

    As soon as I have it done (I am working on it for a customer), I will share it here.

    Just wanted to give everyone a heads up.
  • @tdevlin: This is excellent news. Thank you for doing this. I have a few suggestions for your consideration. Please ignore them if you already thought of these points.

    1. I assume you will allow different passwords for diferent albums.

    2. You may also want to consider allowing more than one password per album. Here is why. Supposing you want to show off a client album to another party. You can give them password access to the same client album (presumably with permission of your client) but only for a week. At the end of the week you disable the second password but your client's original password remains unchanged.

    3. Best to store the passwords in a separate DB table so that if Tristan updates the usual DB tables your table will remain unaffected.

    4. You must already have thought of this but obviously avoid changing the core Zenphoto files as far as possible. Better to add files to /zen and if necessary to add lines to existing files than to replace existing code within files. That is another way to keep it compatible with future versions.
  • trisweb Administrator
    tdevlin - Please consider submitting patches, as this is a feature we'd like to integrate into the core zenphoto (if it's useful and well-designed ;-). I'd love to see your progress so keep us updated!
  • I need something secure to protect the admin file.
    I tried to do from my cpanel but I cant do just the admin.php file.

    If someone knows please advise. Can this be done with htaccess?

    Thanks
  • Update:

    My key goal was to create an album password protection mechanism that works with zenphoto without altering the core code, in fact I didn't want to touch the database either. The reason for this was to help prevent future releases from breaking functionality.

    What I have accomplished so far:
    All passwords for albums (those that are protected) are stored in a yaml file (you can read more about it here: http://www.yaml.org). This file contains the album->foldername and the password for that album. If the album->foldername is not located in the yaml file that album is not protected. Editing of the yaml file is done through an extension to the admin section. When editing an album, one new line of code is added there (again wanted minimal data changes for the core code) that when clicked will take you to a new_file that adds that album->foldername to the yaml file and allows you to type in a password for it. Or if there was already a password, allows you to change or delete it. My customer is currently testing it out for me and will let me know if there are any first round bugs in it. I am also cleaning the code a bit more so I can package it up easier.

    Just wanted to send out an update on the progress.

    Also, many thanks to miriam for the initial code posted, it helped give me the idea for not integrating it totally into zenphoto, but instead abstract much of it. Also, I ripped the login form from the example, I hate typing mundane HTML code out. :)
  • gilou Member
    Hello, first, sorry for my english, i'm french so i'll probably do some mistakes in my message...
    This add for Zenphoto looks great, I've read the "Password Protected Albums" article on ZenphotoHacks page but i don't understand where i must paste the source code on step third...
    I'm using the steril theme , this is what my album.php looks like, can someone helps me ?
    Thanks in advance !

    <?php
    #========================[Private album]===========================
    /* $newwws_password is set in the album specific configuration file, but */
    /* if the name of an album starts starts with an underscore, we consider it to be */
    /* a private album too. The default-password will be zen */
    if (substr(getAlbumTitle(), 0, 1) == "_" && empty($newwws_password)) $newwws_password = "zen";
    /* Check if this is a private album and ask for a password */
    $newwws_passwordfile = $themepath . "/" . $theme . "/" . "newwws_password.php";
    if (empty($newwws_password)){
    $newwws_askforpassword = false;
    } else {
    $newwws_askforpassword = true;
    }
    $newwws_password_soll = $newwws_password;
    $newwws_password_ist = $_POST['newwws_pw'];
    if($_COOKIE["newwws_".strtolower(str_replace(" ", "_", getAlbumTitle()))] == "OK") $newwws_password_ist = $newwws_password_soll;
    if ($newwws_password_ist == $newwws_password_soll) {
    $newwws_askforpassword = false;
    setcookie ("newwws_".strtolower(str_replace(" ", "_", getAlbumTitle())),"OK",time()+1800, "/");
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//FR" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    <title><?php printGalleryTitle(); ?> | <?=getAlbumTitle();?></title>
    <link rel="stylesheet" href="<?= $_zp_themeroot ?>/zen.css" type="text/css" />
    <?php zenJavascript(); ?>
    </head>

    <body>

    <div id="main">

    <div id="gallerytitle">
    <h2><span>" title="Gallery Index"><?=getGalleryTitle();?> | <?php printParentBreadcrumb(); ?></span> <?php printAlbumTitle(true);?></h2>
    <?php echo getGalleryDescription(); ?>
    </div>

    <div id="padbox">

    <div class="albumdesc2"><?php printAlbumDesc(true); ?></div>
    <div id="albums">
    <?php while (next_album()): ?>
    <div class="album">
    <div class="imagethumb">
    " title="View album: <?=getAlbumTitle();?>"><?php printAlbumThumbImage(getAlbumTitle()); ?>

    </div>
    <div class="albumdesc">
    <small><? printAlbumDate("Date Taken: "); ?></small>
    <h3>" title="View album: <?=getAlbumTitle();?>"><?php printAlbumTitle(); ?></h3> <?php printAlbumDesc(); ?>
    </div>
    <p style="clear: both; ">
    </div>
    <?php endwhile; ?>
    </div>

    <div id="images">
    <?php while (next_image()): ?>
    <div class="image">
    <div class="imagethumb">" title="<?=getImageTitle();?>"><?php printImageThumb(getImageTitle()); ?></div>
    </div>
    <?php endwhile; ?>
    </div>

    <?php printPageListWithNav("« précédent", "suivant »"); ?>

    </div>

    </div>

    <div id="credit"><?php printAdminLink('Admin', '', ' | '); ?>Propulsé par ZenPhoto - Edition VirusPhoto</div>
    </body>
    </html>
  • I am having the same problem as gilou, I do not know where to put the code in step 3.
  • jm Member
    tdevlin, any news? Simple password creation is keeping me from moving my client's site from Gallery2 (terrible, ugly beast) to zenphoto. Developing themes in Gallery2 shortens your life! :P

    Adding a password input alongside the album at creation isn't hard, but storing and calling the data is what I can't figure out.
  • bart Member
    I am also looking for this feature. However I have always password-protected my galleries with a .htaccess file (most of you can probably use cpanel for that). I actually have zenphoto installed twice: zenphotopublic and zenphotoprivate
  • jm Member
    A few ideas:
    • an input for a .htpasswd writer. This seems the easiest, so I'll try to work something out later on.
    • Add another field to the table, `albums`. Write to it at album creation.
  • jm Member
    OK, I think I made a little bit of progress using an htaccess & htpasswd solution. My stumbling block right now is how to manage multiple logins/pwds.

    Edit: OK, I'm definitely not smart enough for this. Is anyone else willing to develop this? I'll donate money for this functionality - I just need it soon.
  • La0c00n Member
    @jm: i've replied to you on the Trac of zenphoto !
  • kwanbis Member
    Sorry, i'm looking at the ZenphotoHacks, and in the step 3 says someting i don't get. I have my newwws_password.php with the code of step 2, and i have album.php at this state:

    <?php if (!defined('WEBPATH')) die(); ?>
    <?php
    #========================[Private album]===========================
    /* $newwws_password is set in the album specific configuration file, but */
    /* if the name of an album starts starts with an underscore, we consider it to be */
    /* a private album too. The default-password will be zen */
    if (substr(getAlbumTitle(), 0, 1) == "_" && empty($newwws_password)) $newwws_password = "zen";
    /* Check if this is a private album and ask for a password */
    $newwws_passwordfile = $themepath . "/" . $theme . "/" . "newwws_password.php";
    if (empty($newwws_password)){
    $newwws_askforpassword = false;
    } else {
    $newwws_askforpassword = true;
    }
    $newwws_password_soll = $newwws_password;
    $newwws_password_ist = $_POST['newwws_pw'];
    if($_COOKIE["newwws_".strtolower(str_replace(" ", "_", getAlbumTitle()))] == "OK") $newwws_password_ist = $newwws_password_soll;
    if ($newwws_password_ist == $newwws_password_soll) {
    $newwws_askforpassword = false;
    setcookie ("newwws_".strtolower(str_replace(" ", "_", getAlbumTitle())),"OK",time()+1800, "/");
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    <title><?php printGalleryTitle(); ?> | <?php echo getAlbumTitle();?></title>
    <link rel="stylesheet" href="<?php echo $_zp_themeroot ?>/zen.css" type="text/css" />
    <?php zenJavascript(); ?>

    </head>

    <body>

    <div id="main">

    <div id="gallerytitle">
    <h2><span>" title="Gallery Index"><?php echo getGalleryTitle();?> | </span> <?php printAlbumTitle(true);?></h2>
    </div>

    <?php printAlbumDesc(true); ?>

    <div id="images">
    <?php while (next_image()): ?>
    <div class="image">
    <div class="imagethumb">" title="<?php echo getImageTitle();?>"><?php printImageThumb(getImageTitle()); ?></div>
    </div>
    <?php endwhile; ?>
    </div>

    <?php printPageListWithNav("« prev", "next »"); ?>

    <div id="enableSorting">
    <?php printSortableAlbumLink('Click to sort album', 'Manual sorting', NULL, 'sort'); ?>
    </div>

    </div>

    <div id="credit"><?php printAdminLink('Admin', '', ' | '); ?>Powered by zenphoto</div>

    </body>
    </html>
  • kwanbis Member
    (looks like all of us newbies don't get step 3)
  • kwanbis Member
    and before somebody responds, where do i set the password?
  • @kwanbis-

    I have it working on my gallery at http://www.thinkdreams.com/devzen. Make sure you name all the galleries you want to password protect with underscores `_`. The code you need to add (which may look different in whatever theme you use) is (and this is based on default theme):

    `<?php<br />
    if ($newwws_askforpassword){

    include("$newwws_passwordfile");

    } else { ?>



    <?php } ?>`

    What I did was add in the lines miriam mentioned:

    `<?php<br />
    if ($newwws_askforpassword){

    include("$newwws_passwordfile");

    } else {

    /* place the original thumbs generating code here */

    /* or include another php-file with the thumbs-code */

    include("$newwws_thumbs_php");

    }

    ?>`

    right above the lines in the default theme that look like:

    ``

    which generate the thumbnails you see in the album display page. Then just cut n paste the thumbnail code into the "miriam" code shown above (making sure to use proper php script start and end statements (`<?php` and `?>`). Once that's done, it should work fine.

    Hopefully that will get you started on the right path.
  • Oh, and the password is set in the very top of the album.php once you make the code changes. Look for:

    `$newwws_password = "zen";`

    at or around line 6 in the album.php.

    And if anyone looks at my gallery, the password is bob, not zen. I was experimenting. I chose "bob". Don't know why. ;)
Sign In or Register to comment.