3 ms·
Surely you'd store their birthdate (or maybe birth year and month for privacy reasons). Then you only allow people who you know are older than 21, those born be
by Natfan 4y ago
Surely you'd store their birthdate (or maybe birth year and month for privacy reasons). Then you only allow people who you know are older than 21, those born before (not in) 2001-11 (based on currentYear of 2022). With the magic of modern JavaScript, this shouldn't be too hard:
let birthday = "1998-08" # This value is taken from the user's verified credentials, in my case September 1998.
let ageRestriction = 21
let legalDate = new Date(new Date().setFullYear(new Date().getFullYear() - ageRestriction))
let birthdayDate = new Date(birthday)
if (legalDate > birthdayDate) console.log("Is that cash or card?")
else console.log("Sorry, you're not old enough.")
e: I didn't fully read OOP's comment about not wanting to reveal age, however I still feel that YYYY-MM is a valid option for age verification. It allows for the most privacy while impacting the smallest group of people, and in those cases you would effectively need to be 21 and a month old to enter these bars, without some other form of legal ID.
e2: Reading through the article after commenting (I know, I'm terrible and you can all violently detest me if you wish), there is an "ID card" example which clearly states the user's date of birth. Surely this is a prime use-case for OOP?
- NovemberWhiskey 4y agoWho is the "you" in this? The party that knows the truth of your personal data isn't the same party that you want to rely on your personal data. The idea here is, say, the DMV in your state knows your age. But you don't want to show your driver's license credential which includes your home address and exact birthdate at a bar, because it's not their need-to-know. So you can ask the DMV to issue you with a "drinker's permit" which only has your photo and ageOver=21. A bar just validates you match your picture and knows you're of legal drinking age.
- boosteri 4y agoGenuinely interested what calendar you're using where 08 represents September?
- mmarti 4y agoIgnoring the specific example given, JavaScript Date objects use zero-based months depending on how you construct or interact with them, so I'm assuming the OP was thinking of a zero-based example and just wrote it out using 08 in the string.
- naikrovek 4y agomonths sometimes start at zero in programming languages. days of the week, as well, often.
- mastazi 4y agothere is also the problem that in some locales the first day of the week is thought to be Sunday rather than Monday, so regardless of 0-indexing or not, we can't even agree on that IRL :-D
- deleted 4y ago[deleted]
- inopinatus 4y agoHeck, I can't remember how old I am. Pretty sure I'm over 21 though, and most authorities would agree after a cursory visual inspection. There are also folks who: * Can only guess at the day, month, and/or year of their own birth. * Cannot currently tell you their date of birth (e.g. incapacitated, incommunicado, unconscious, absent, or forgot. what year is it?) * Cannot prove their date of birth (e.g. records destroyed) * Mix up their relatives date of birth (the probability of this approaches 1 asymptotically as the family size increases) * Use a different date format to you, with consequently ambiguous interpretation Similar impedance mismatches between information and permission exist in almost all authorization domains. Consequently, the only credentials with general applicability are those capable of asserting a right or validating a claim, not those that merely sign data.