Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
3 posts Page 1 of 1

Is there any simple way with Couch to password protect a page, without storing the actual password in the source code.

Basically, I have a page called "contrats.php".
Each entries should not be accessible without a password, and that password would a value inside a region named "my_uid".

I have made a simple image to show what I need.
Any idea how to do it?

capture.png (438.22 KiB) Viewed 948 times

**Important to note. I cannot create a page, where you enter a code and get redirected to the right contract, since someone could just enter every contract numbers and access all the contracts. Also, the direct link will be sent to the clients. So just to make sure someone cannot just change the URL and access any contracts, I would like a very simple protection, with the contract number.

If I send a contract to a client, he knows what the number of the contract will be, so he will be able to unlock the page very easily. But someone that doesn't know what the contract number is, even if he has the link, won't be able to unlock the page.
That's why I would need something on the template page, so that it applies to every pages, and always use the "my_uid" region data as the password.
Following is a generic solution that, perhaps, you'll find useful.

Create a password field as follows -
Code: Select all
<cms:editable name='my_password' label='Password' type='text' searchable='0' width='200' validator='max_len=20' />

Now modify the page-view of the template to make it as follows -
Code: Select all
<cms:if k_is_page>

    <cms:set given_password="<cms:get_cookie 'page_password' />" />

    <cms:if my_password eq '' || (given_password eq my_password)>
        <!-- OK to show contents of the page -->
        <h1><cms:show k_page_title /></h1>

    <cms:else />
        <h2>This page is password protected.</h2>
        <p>To view the contents please enter your password below</p>
        <cms:form method='post' anchor='0'>

            <cms:if k_success >
                <cms:set_cookie name='page_password' value=frm_password />
                <cms:redirect k_page_link />

            <cms:if k_error >
                <font color='red'><cms:each k_error ><cms:show item /><br /></cms:each></font>
            <cms:input name='password' label='Password' type='text' maxlength="10" validator='max_len=20' required='1' /><br>
            <button name='submit' type="submit">Enter</button>

@Larin, you don't have to create the password field as you already have one that holds the password.
Just substitute 'my_password' in the line shown below with the name of your field -
Code: Select all
<cms:if my_password eq '' || (given_password eq my_password)>

Hope it helps. Do let me know.
Works perfectly.
Thanks a lot KK. Once again, amazing support!

This is a really useful solution for anybody that wants to password protect a page with Couch.

Thanks again!
3 posts Page 1 of 1