Beta Key System.

Status
Not open for further replies.

Joxel

Meester Eubbo
Jul 23, 2013
42
0
I don't know if there is a beta key system around here for a Roleplay Hotel.

I was wondering if someone nice could help me with one ;)
 

Jeffrey

Devbest Indian Tech Support
FindRetros Moderator
Feb 5, 2013
1,180
412
Learn PHP? Thats the best way to learn to make one. or google...
I would suggest you to go to this link, but its infracting devbest's rule.
 

Sledmore

Chaturbate Livestreamer
Staff member
FindRetros Moderator
Jul 24, 2010
5,195
3,907
Here is something quick for you to work on, it is using the MySQL extension so make sure you're running a PHP installation before PHP 5.5.0.

PHP:
CREATE TABLE `cms_beta_keys` (
`id`  int(11) NOT NULL AUTO_INCREMENT ,
`beta_key`  varchar(25) NULL DEFAULT '' ,
PRIMARY KEY (`id`));
PHP:
<?php
 
function filter($var)
{
return mysql_real_escape_string(stripslashes(htmlspecialchars($var)));
}
 
if (isset($_POST['submit'])) {
if (empty($_POST['beta_key'])) {
echo 'You didn\'t enter a BETA key!';
} else {
mysql_connect("localhost", "root", "password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
 
if (mysql_num_rows(mysql_query("SELECT `beta_key` FROM `cms_beta_keys` WHERE `beta_key` = '".filter($_POST['beta_key'])."'")) == 0) {
echo 'That isn\'t a valid BETA key!';
} else {
echo 'Beta key is valid!';
//Do what you want here (set a session or cookie for their access to register
//mysql_query("DELTE FROM `cms_bet_keys` WHERE `beta_key` = '".filter($_POST['beta_ket'])."' LIMIT 1");
}
}
}
 
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <title>Welcome - BETA Key.</title>
    </head>
 
<body>
<form action="#" method="POST">
<input type="text" name="beta_key"><br/>
<input type="submit" name="submit" value="Submit!">
</form>
</body>
</html>
 

Joxel

Meester Eubbo
Jul 23, 2013
42
0
Here is something quick for you to work on, it is using the MySQL extension so make sure you're running a PHP installation before PHP 5.5.0.

PHP:
CREATE TABLE `cms_beta_keys` (
`id`  int(11) NOT NULL AUTO_INCREMENT ,
`beta_key`  varchar(25) NULL DEFAULT '' ,
PRIMARY KEY (`id`));
PHP:
<?php
 
function filter($var)
{
return mysql_real_escape_string(stripslashes(htmlspecialchars($var)));
}
 
if (isset($_POST['submit'])) {
if (empty($_POST['beta_key'])) {
echo 'You didn\'t enter a BETA key!';
} else {
mysql_connect("localhost", "root", "password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
 
if (mysql_num_rows(mysql_query("SELECT `beta_key` FROM `cms_beta_keys` WHERE `beta_key` = '".filter($_POST['beta_key'])."'")) == 0) {
echo 'That isn\'t a valid BETA key!';
} else {
echo 'Beta key is valid!';
//Do what you want here (set a session or cookie for their access to register
//mysql_query("DELTE FROM `cms_bet_keys` WHERE `beta_key` = '".filter($_POST['beta_ket'])."' LIMIT 1");
}
}
}
 
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <title>Welcome - BETA Key.</title>
    </head>
 
<body>
<form action="#" method="POST">
<input type="text" name="beta_key"><br/>
<input type="submit" name="submit" value="Submit!">
</form>
</body>
</html>


I can probably do something with this code, but i'm not looking to put it on the register :/ I was looking to let all users register, then add the beta key on the 'me.php' page. and if they try to access the client it gives them an error.
 

Sledmore

Chaturbate Livestreamer
Staff member
FindRetros Moderator
Jul 24, 2010
5,195
3,907
I can probably do something with this code, but i'm not looking to put it on the register :/ I was looking to let all users register, then add the beta key on the 'me.php' page. and if they try to access the client it gives them an error.


You should of said, lol. - What CMS?
 

Heaplink

Developer & Designer
Nov 9, 2011
510
173
It's quite easy to make such a system, even secure.

- Use PDO/MySQLi - not the (soon to be deprecated) mysql functions.
- Create 2 tables;
betakeys (id, betakey)
The id is a PRIMARY KEY
The betakey column will contain the generated beta key.
users (id, [...], betakey_id, hasbeta)
The [...] are your own columns (username, password, email, etc)
The betakey_id is a relation to betakeys.id column
The hasbeta is a boolean (TRUE or FALSE) wether the user has beta access. This is what you use to check when the client is opened, etc.

You can use this function to generate a nice and simple key. This could be triggered when you generate keys in your backend and insert them into the betakeys table

PHP:
function generate_key()
{
    $character_set_array = array();
    $character_set_array[] = array('count' => 4, 'characters' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ');
    $character_set_array[] = array('count' => 4, 'characters' => '0123456789');
    $temp_array = array();
    foreach ($character_set_array as $character_set) {
        for ($i = 0; $i < $character_set['count']; $i++) {
            $temp_array[] = $character_set['characters'][rand(0, strlen($character_set['characters']) - 1)];
        }
    }
    shuffle($temp_array);
    return implode('', $temp_array);
}

To have unique keys, we check if the keys already exists. If they don't we add them to the database, otherwise we generate a new key and check again.

Then when they register, it should validate all the fields. We also check wether the entered betakey exists in the betakeys table and if a user doesn't already have it. If it does, we simply put the found betakey's ID in the betakey_id column and the hasbeta to TRUE.

Another method would be to remove the betakey_id column from users and simply have hasbeta. Then delete the registred keys from the betakeys table - this is better in performance, as you won't have a clusterfuck of rows, and also doesn't limit the amount of unique keys, that can be registred.
 

Kaz

BooYah
Staff member
Nov 16, 2010
3,064
1,025
Edit of RealityCMS, Big edit by my man Lucas ;) if you want i can get you tv dets via PM.
Then give your 'man' code and get him to implement the code.
It really isnt hard.

Depending how you want to do it, you could add 2 columns to your users table:
betaKey & isBeta
When the user 'signs up for beta' they will have a code (how you wish for them to receive this code is your own choice)
And then there could be an activation page which would then check that the Beta Key is the same as the user wishing to use it.
If they match, then update the 'isBeta' to 1 or yes and if not, then give them an error.

Then upon the user visiting client.php you will have a check in place:
you will use an if statement for the following,
if the user trying to access isBeta = yes then allow access
else send them back to /me.php
 
Status
Not open for further replies.

Users who are viewing this thread

Top