The only legal way to play Minecraft online is to buy the game on the developer's website, giving you access to both downloadable and browser versions of the game. If you want to try the game first, there is a free demo available on the website.
Minecraft is also available on Xbox 360, Xbox One, Playstation 3, and Playstation 4. Additionally, you can buy the Pocket Addition for mobile devices, such as iOS, Android, Windows Phone and Amazon Kindle Fire. Buying one version of the game does not give you access to other versions of the game. For example, downloading the Xbox 360 version will not give you a PC copy.
If you decide to purchase the PC or Mac version, you will first need to create a Mojang account. This account can also be used to purchase any games that Mojang makes in the future. You will need to put in your E-mail address, then choose a password. Afterwards, select a payment option, such as a Mastercard. When you have paid for the game, you will receive a link in your E-mail inbox to a special download page. Alternately, you can log in with your newly created Mojang account and download it from the site.