A little while back i decided i would like to make sure that any user signing up for my server website would in fact be a real Minecraft player with a valid username.
I wrote a small script to do just that, it receives a username and checks the username against Minecraft.net's list of premium usernames.
Hope this helps people out, if anyone has any questions feel free to comment here with them.
Script:
<?php
// Code written by DanielRHarris (DanielRH)
// Code written for VectronCraft (IP: MC.VectronCraft.com -- Website: www.VectronCraft.com)
// PHP Function to check whether the minecraft username ($mcUser) is a premium minecraft account holder
function check_user($mcUser)
{
// $check_mcUser gets the contents of the file from minecraft.net that does the checking for premium user
$check_mcUser = file_get_contents('http://www.minecraft.net/haspaid.jsp?user='.$mcUser.'');
// If $check_mcUser is true (premium user), it executes the code within
if ($check_mcUser == 'true') {
echo 'Username Is Premium!';
}
// If $check_mcUser is not true, it executes the code within the else statement
else {
echo 'Username Not Premium.';
}
}
// Please comment/uncomment a method you would like to use to recieve the username (leave only one activated at once and comment the others out with a // at the begginning of the line
// Gets the username from a form submit, or via url (eg. www.example.com/checkuser.php?mcUser=DanielRHarris):
$mcUser = $_GET["mcUser"];
// Declares the username right here within the quotes:
//$mcUser = 'DanielRHarris';
// Executes function that checks whether the user is a premium minecraft account holder
check_user($mcUser);
?>
Just put this into a .php page and upload it to a webhost then navigate to the page and add a ?mcUser=USERNAMEHERE to the url and hit enter, that will check to see if its valid and tell you if it is.
IF you want it to do something special when it checks whether its a premoum account or not, your gonna have to write special PHP code for that.
Just thought I'd make the code a little easier for some people. Create a file called 'Minecraft.class.php' and add the php code:
class Minecraft {
// Code written by DanielRHarris (DanielRH)
// Code written for VectronCraft (IP: MC.VectronCraft.com -- Website: www.VectronCraft.com)
// PHP Function to check whether the minecraft username ($mcUser) is a premium minecraft account holder
function check_user($mcUser)
{
// $check_mcUser gets the contents of the file from minecraft.net that does the checking for premium user
$check_mcUser = file_get_contents('http://www.minecraft.net/haspaid.jsp?user='.$mcUser.'');
// If $check_mcUser is true (premium user), it executes the code within
if ($check_mcUser == 'true') {
return true;
}
// If $check_mcUser is not true, it executes the code within the else statement
else {
return false;
}
}
}
Then all you have to do is the follwing:
include('Minecraft.class.php');
$verify = new Minecraft();
$mc_user = $_GET['mc_user'];
$valid = $verify::check_user($mc_user);
if($valid) {
//user is premium
} else {
//user is not premium
}
Only thing i have a problem with with this script is it can be used in a malicious way. but all in all a great idea and a fantastic way to validate premium users
Very nice script. I myself made one for C# .NET for anyone making tools with that:
//Login Form gets username and password. (I used this in a Win Forms program)
WebClient doanloadClient = new WebClient();
//Try to download Minecraft login reply.
//Used version 99 because the current launcher is version 13. Anything larger is safe, anything smaller is not.
try
{
downloadClient.DownloadFile("http://login.minecraft.net?user=" + loginForm.Username + "&password=" + loginForm.Password + "&version=99", <DESTINATION FILE PATH>);
}
catch
{
//Failed to download the Minecraft login reply.
}
//Get the reply and delete.
string reply = File.ReadAllText(<PATH TO DOWNLOADED FILE>);
File.Delete(<PATH TO DOWNLOADED FILE>);
//Compare reply.
if (reply == "Bad login")
{
//"Bad login" = invalid information.
}
else if (reply == "User not premium")
{
//"User not premium" = user hasn't bought Minecraft
}
//Get username for direct launch of Minecraft.
username = loginForm.Username;
//Get session ID for direct launch of Minecraft.
sessionID = reply;
sessionID = sessionID.Substring(sessionID.IndexOf(':') + 1);
sessionID = sessionID.Substring(sessionID.IndexOf(':') + 1);
sessionID = sessionID.Substring(sessionID.IndexOf(':') + 1);
sessionID = sessionID.Substring(0, sessionID.IndexOf(':'));
I'm using this in my program (see siggy!) to be sure the user doesn't steal the game.
Very nice script. I myself made one for C# .NET for anyone making tools with that:
if (reply == "Bad login")
{
//"Bad login" = invalid information.
}
else if (reply == "User not premium")
{
//"User not premium" = user hasn't bought Minecraft
}
I'm using this in my program (see siggy!) to be sure the user doesn't steal the game.
Problem with only doing this check is that they could type an incorrect password with a mojang.com account and get free access to the game. The reason behind my logic is that if they don't enter the email address, it will return "Account migrated, use e-mail as username." no matter what. I just tried it with my username, rathar than my email address, and got that message.
A bit OT but; you have a version switcher/launcher and I have a modded jar downloader ;D (too much effort to install mods on the mac)
Problem with only doing this check is that they could type an incorrect password with a mojang.com account and get free access to the game. The reason behind my logic is that if they don't enter the email address, it will return "Account migrated, use e-mail as username." no matter what. I just tried it with my username, rathar than my email address, and got that message.
A bit OT but; you have a version switcher/launcher and I have a modded jar downloader ;D (too much effort to install mods on the mac)
Duely noted. Will patch tonight to prevent this and edit this post with the new code. And I'm not sure I get the meaning behind your OT statement.
Basically, I was stating that you were using login code to download different versions of minecraft, while I was using it to download a modded jar. I do it because it is overly complicated to install mods on a mac. Therefore, I created a shell script that will install mods for me, then I (or friends) could proceed to download the modded jar in a more legal manner from anywhere in the world.
Ah, I see. One feature I want to have is the ability to preload different versions with mods upon download, but that would require a database of mods to download, meaning I actively search for them or they register. I know for a fact that until Patchcraft is very popular, that won't happen.
The altered code is as follows:
WebClient doanloadClient = new WebClient();
//Set to true because the code tests for problems and not a lack thereof.
//Any problem detected will set to false, and the loop will set back to true for next run.
bool verified = true;
//Login loop.
//As is, this code results in a a loop that will continue until the user gets the information correct.
//This can be cut to any number of times by using a "tries" integer variable.
do
{
//Login Form gets username and password.
//Set verified to true for current run.
verified = true;
//Try to download Minecraft login reply.
//Used version 99 because the current launcher is version 13. Anything larger is safe, anything smaller is not.
try
{
downloadClient.DownloadFile("http://login.minecraft.net?user=" + loginForm.Username + "&password=" + loginForm.Password + "&version=99", <DESTINATION FILE PATH>);
}
catch
{
//Failed to download the Minecraft login reply.
}
//Get the reply and delete.
string reply = File.ReadAllText(<PATH TO DOWNLOADED FILE>);
File.Delete(<PATH TO DOWNLOADED FILE>);
//Compare reply.
if (reply == "Bad login")
{
//"Bad login" = invalid information.
verified = false;
}
else if (reply == "User not premium")
{
//"User not premium" = user hasn't bought Minecraft
verified = false;
}
else if (reply == "Account migrated, use e-mail as username.")
{
//"Account migrated, use e-mail as username." = account has been migrated.
//User should use Mojang email in the username box instead of his/her actual MC username
verified = false;
}
} while (!verified);
//Get username for direct launch of Minecraft.
username = loginForm.Username;
//Get session ID for direct launch of Minecraft.
sessionID = reply;
sessionID = sessionID.Substring(sessionID.IndexOf(':') + 1);
sessionID = sessionID.Substring(sessionID.IndexOf(':') + 1);
sessionID = sessionID.Substring(sessionID.IndexOf(':') + 1);
sessionID = sessionID.Substring(0, sessionID.IndexOf(':'));
Rollback Post to RevisionRollBack
The most user friendly version switcher: Get it here!
Ah, I see. One feature I want to have is the ability to preload different versions with mods upon download, but that would require a database of mods to download, meaning I actively search for them or they register. I know for a fact that until Patchcraft is very popular, that won't happen.
The altered code is as follows:
WebClient doanloadClient = new WebClient();
//Set to true because the code tests for problems and not a lack thereof.
//Any problem detected will set to false, and the loop will set back to true for next run.
bool verified = true;
//Login loop.
//As is, this code results in a a loop that will continue until the user gets the information correct.
//This can be cut to any number of times by using a "tries" integer variable.
do
{
//Login Form gets username and password.
//Set verified to true for current run.
verified = true;
//Try to download Minecraft login reply.
//Used version 99 because the current launcher is version 13. Anything larger is safe, anything smaller is not.
try
{
downloadClient.DownloadFile("http://login.minecraft.net?user=" + loginForm.Username + "&password=" + loginForm.Password + "&version=99", <DESTINATION FILE PATH>);
}
catch
{
//Failed to download the Minecraft login reply.
}
//Get the reply and delete.
string reply = File.ReadAllText(<PATH TO DOWNLOADED FILE>);
File.Delete(<PATH TO DOWNLOADED FILE>);
//Compare reply.
if (reply == "Bad login")
{
//"Bad login" = invalid information.
verified = false;
}
else if (reply == "User not premium")
{
//"User not premium" = user hasn't bought Minecraft
verified = false;
}
else if (reply == "Account migrated, use e-mail as username.")
{
//"Account migrated, use e-mail as username." = account has been migrated.
//User should use Mojang email in the username box instead of his/her actual MC username
verified = false;
}
} while (!verified);
//Get username for direct launch of Minecraft.
username = loginForm.Username;
//Get session ID for direct launch of Minecraft.
sessionID = reply;
sessionID = sessionID.Substring(sessionID.IndexOf(':') + 1);
sessionID = sessionID.Substring(sessionID.IndexOf(':') + 1);
sessionID = sessionID.Substring(sessionID.IndexOf(':') + 1);
sessionID = sessionID.Substring(0, sessionID.IndexOf(':'));
It would also probably be easier to use WebClient.DownloadString() function instead. e.g.
It might, but when testing my code I had problems and this was one of the things that changed until it began working. I never bothered to try it again once it started working. I'll try tonight.
Rollback Post to RevisionRollBack
The most user friendly version switcher: Get it here!
Can't you just set online-mode=true in your server.properties file?
While this forces the player to own minecraft in order to join the server, it doesn't tie the user account to a forum for example. And in Drakken's case, that wouldn't prevent someone from downloading and playing minecraft in a single player world.
In summary; That works for the minecraft server, but not for other things. (like a website, which this topic was originally about)
frostyfrog is correct. Our situations call for more complex security measures because we are dealing with access to the game itself, modded or not, current version or not. We don't want the user who hasn't bought the game to be able to play it at all. I am personally very much against pirating. You are literally robbing the creators of hours upon hours of effort. I try as hard as I can to support the creators of whatever I use by buying every piece of software I have, and I wish the rest of the world were just as honest.
Rollback Post to RevisionRollBack
The most user friendly version switcher: Get it here!
I wrote a small script to do just that, it receives a username and checks the username against Minecraft.net's list of premium usernames.
Hope this helps people out, if anyone has any questions feel free to comment here with them.
Script:
Long live the creeper! - Ssssss.....
/DanielRH
Just put this into a .php page and upload it to a webhost then navigate to the page and add a ?mcUser=USERNAMEHERE to the url and hit enter, that will check to see if its valid and tell you if it is.
IF you want it to do something special when it checks whether its a premoum account or not, your gonna have to write special PHP code for that.
Then all you have to do is the follwing:
Want a place to advertise your Minecraft server? try MyMCStatus.net now!
It's a nice script, although I use the following code on my site:
in Minecraft.class.php
In mclogin.php
Signaturecraft is back!@SigCraft
How to use:
@frostyfrog
Nice way to get minecraft accounts...
I'm using this in my program (see siggy!) to be sure the user doesn't steal the game.
Problem with only doing this check is that they could type an incorrect password with a mojang.com account and get free access to the game. The reason behind my logic is that if they don't enter the email address, it will return "Account migrated, use e-mail as username." no matter what. I just tried it with my username, rathar than my email address, and got that message.
A bit OT but; you have a version switcher/launcher and I have a modded jar downloader ;D (too much effort to install mods on the mac)
Signaturecraft is back!@SigCraft
Duely noted. Will patch tonight to prevent this and edit this post with the new code. And I'm not sure I get the meaning behind your OT statement.
EDIT: New code posted below.
Signaturecraft is back!@SigCraft
The altered code is as follows:
It would also probably be easier to use WebClient.DownloadString() function instead. e.g.
Want a place to advertise your Minecraft server? try MyMCStatus.net now!
While this forces the player to own minecraft in order to join the server, it doesn't tie the user account to a forum for example. And in Drakken's case, that wouldn't prevent someone from downloading and playing minecraft in a single player world.
In summary; That works for the minecraft server, but not for other things. (like a website, which this topic was originally about)
Signaturecraft is back!@SigCraft