This is my first php script. I actually code in vb.net.. I am making this licensing system for .net applications. This licensing system has a manager which the admin can easily control and view. Also Iam making a class library to login and register for the same. I have succeeded in doing so using only vb.net code but as the credentials need to be stored inside the application there always is a threat. Using php this problem can be overcomed somewhat :tongue: . So I decided to make the login + register system using this kinda php scripts. I am using a only admin read,write text file instead of a mysql database ( Easily maneagable for all hosting services ). So, I have come up with this following piece of code and I need some help in the confirming the login part. The text file is like this :
username password hwid lastdate membershiptype
All separated by 'space' and one account per line. I hope I have given enough information, If extra information is needed, I will give it.
<?php
$user = addslashes($_GET['username']);
$pass = addslashes($_GET['password']);
$username = "theusername";
$password = "thepassword";
$url = "mywebsite.com/file.txt";
$hostname= "ftp://$username:$password@$url";
$contents = file_get_contents($hostname);
// That gives me the txt file which can only be read and written by the admin
if (strpos($contents,$user) !== false) {
// Need code here to check if the adjacent word and the $pass are same to establish a successfull login
} else {
echo "Username does not exist, please register"
}
?>
Here try this, hope it helps:
file.txt would need tobe in this format, values seperated by :
, spaces are not a good way to seperate values.
username:password:hwid:lastdate:membershiptype
The PHP bit:
<?php
$user = $_GET['username'];
$pass = $_GET['password'];
if(check_auth(get_auth(),$user,$pass)==true){
echo 'Yes';
}else{
echo 'No';
}
/**
* This function will grab the text file and create a user array
*
* @return array(0=>username,1=>password)
*/
function get_auth(){
$username = "theusername";
$password = "thepassword";
$url = "mywebsite.com/file.txt";
$location = "ftp://$username:$password@$url";
$users = file($location);
function split_auth(&$value){
$value = explode(':',$value);
}
array_walk($users,'split_auth');
return $users;
}
/**
* This Function will check the username and password
* against the users array
*
* @param array $users
* @param string $username
* @param string $password
* @return bool (true|false)
*/
function check_auth($users,$username,$password){
foreach($users as $user){
if($user[0]==$username && $user[1]==$password){
return true;
}
}
return false;
}
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.