Registration with personal key

Hi there,

I am currently working on a website where users may only sign-up as when they have received a personal key. This generated key should only work for one sign-up. All of the keys are generated beforehand (outside of the kirby) and I assume will be in an Excel sheet.

I read about creating virtual pages programatically with a .csv file as input, but it seems like overkill to create a virtual page for every key, right?

So then I was thinking about having one page that cannot get accessed by users and programatically adding fields to that page containing the keys. Is there a way to do it and does it make sense to do it this way? Is it then possible to loop trough the fields of that page on sign-up and if that key exists? I guess it’s not so hard to then also programmatically delete that field, if I got this far.

Would love to hear your thoughts on this!

Thank you!

You would have to be very careful here. It is possible for the CSV file to end up in the media folder, and also publicly accessable, which means someone can easily get hold of all your keys. It would be better use a Database at least, for the keys, with a superstrong password on it and change it often.

Thanks, that’s a fair point! Putting the keys into a secured database is surely the better and more secure option. I just read about how I can query the database and extract the values, however I don’t really understand how that works exactly. I can select the row and search for a key but what I’m not quite sure what I get back by the Kirby Db::select method.

What I’m doing is:

$personalKeys = Db::query('SELECT * FROM personalkeys WHERE personalkey = "' . $enteredKey . '" AND taken = 0');
dump($personalKey)

which returns this:

Kirby\Toolkit\Collection Object
    (
        [0] => 0
    )

How do I work with this object and where can I find more information? I expected, that I could use something like ->num_rows or something similar.

The guide at https://getkirby.com/docs/guide/database#where-clause extracts the values by using a foreach loop, but I want to understand the object I’m dealing with better.

EDIT:
What I wanted to achieve is definitely possible with the foreach iteration, as I can check if the loop runs at all or not, but I would still like to learn more about this object, that gets returned here.

Do a dump($personalKeys->toArray()) to see what’s in the Collection.

1 Like