Advanced search  

News:

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

Pages: [1]   Go Down

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

0 Members and 1 Guest are viewing this topic.

viper85

  • 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
    if(!/^\d{1,2}\/\d{1,2}\/\d{4}$/.test(dateString))
        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;
            else
                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.
Logged

ron4mac

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Posts: 1001
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. http://www.totalwine.com/
Logged
Pages: [1]   Go Up
 

Page created in 0.015 seconds with 20 queries.