Advanced search  


cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.

Pages: [1]   Go Down

Author Topic: Verifying age before allowing registration  (Read 2736 times)

0 Members and 1 Guest are viewing this topic.


  • Coppermine newbie
  • Offline Offline
  • Posts: 1
Verifying age before allowing registration
« on: July 08, 2018, 06:30:05 am »

I'm getting ready to create a gallery that will post image from another site that the user decided he didn't have the time to continue to update. He was using some other rudimentary photo gallery, and in my attempt to put my own spin on it, I've decided to use Coppermine. However, some of the content that will be in this gallery will be adult-oriented, and I want to make sure that any person who registers to the site is above 18 years old.

I found Andre's fix in this thread for how to make the optional fields required. I have changed the code to make Optional Field 1 the birthday.

However, it's been over a decade since I last did any JavaScript coding, and I must say that my skills have gone from rusty, to almost non-existent. Basically, what I'm wanting to do is have two functions:
  • Check that the input in Optional Field 1 fits a given template MM/DD/YYYY or YYYY/MM/DD
  • Check if Current year minus birth year is greater than or equal to 18.
    • If it's less than, decline registration.
    • If it's equal to, then check the month and day.
    • If it's greater than, allow the registration to go through properly.

Based on different snippets of code I've found on the internet, I've constructed the following, but I'm getting to the point where I don't know where I'm going anymore.

Code: [Select]
// Validates that the input string is a valid date formatted as "mm/dd/yyyy"
function isValidDate(dateString)
    // First check for the pattern
        return false;

    // Parse the date parts to integers
    var parts = dateString.split("/");
    var day = parseInt(parts[1], 10);
    var month = parseInt(parts[0], 10);
    var year = parseInt(parts[2], 10);

    // Get the current date broken into individual componenets
    var todayYear = new Date();
    document.getElementById("demo").innerHTML = todayYear.getFullYear();
    var todayMonth = new Date();
    document.getElementById("demo").innerHTML = todayMonth.getMonth();
    var todayDay = new Date();
    document.getElementById("demo").innerHTML = todayDay.getDate();

    // Check the ranges of month and year
    if(year < 1000 || year > 3000 || month == 0 || month > 12)
        return false;

    var monthLength = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];

    // Adjust for leap years
    if(year % 400 == 0 || (year % 100 != 0 && year % 4 == 0))
        monthLength[1] = 29;

    // Check the range of the day
    return day > 0 && day <= monthLength[month - 1];

    // Check if age is greater than 18
    if((todayYear - year) > 18)
        return true;
    elseif((todayYear - year) < 18)
        return false;
    elseif((todayYear - year) = 18) {
        if(((todayMonth + 1) - month) > 0)
            return true;
        elseif(((todayMonth + 1) - month) = 0)
            if(((todayDay + 1) - day) > 0)
                return true;
                return false;
        elseif(((todayMonth + 1) - month) < 0)
            return false;

I'm also not sure what lines of code I'd need to amend and in which files to make these changes. (Although I'm pretty sure it'd be in registration.js and registration.php.)

If anyone can help me with this, I'd be very grateful.


  • Administrator
  • Coppermine addict
  • *****
  • Country: us
  • Offline Offline
  • Posts: 2026
Re: Verifying age before allowing registration
« Reply #1 on: July 08, 2018, 01:29:16 pm »

As you must know, there is actually no way that you can truly verify a registrant's age. So what you are trying to do can be made much simpler. At the time of registration, calculate the date they would have been born to be over 18. Display that date and ask whether they were born before it with yes/no radio buttons. The method is used for many alcohol web stores.
Pages: [1]   Go Up

Page created in 0.018 seconds with 19 queries.