Pin code generator with php

Pls, i need help with generating random numbers that would grant access to students to log in to the website to check results or admission status. the codes are to be stored in a MYSQL database and PHP would have tpo reference the db before granting access to the student.

it would be cool too if the code could have stuff on log in rate and also grant a limited amount of acess to the student say 5 TIMES.

thanks.

Do you have any code yet? Kinda hard to help without knowing what you’ve done so far. :slight_smile:

I’m not going to code everything for you but this is how you create a random pincode (it’s simple).


// Lets say the code is 4 numbers
$pincode = rand(0,9).rand(0,9).rand(0,9).rand(0,9);

can i add letters a-z and A-Z, to get more random codes

Sure:

$alphabet = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
$alphabet[rand(0, 25)];

thanks, pls would it be possible for me to pass in a variable and have this PHP script genrate random codes from it. e.g “A67889” and the script then create a random code.

What do you mean by a random code from A67889?

the code above could be a receipt number and i want to the program to generate say an encryted code from it, like what MD5, the asp code does.


$var = 'fg45tgfd';
$md5_hash = md5($var);


Uhm…

Pin numbers (in most cases) need to be unique. For your purpose, they definitely need to be unique. So if you are going to randomly generate Pins, you need to check the database to see if one exist already, before allowing someone to use the generated Pin.

If hes talking about a reciept, the id will always be unique and therefore when you md5 it it still will.