Pass on php key

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

PHP Example For KeyAuth Authentication System

License

KeyAuth/KeyAuth-PHP-Example

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

PHP example for the https://keyauth.cc authentication system.

Video Tutorial:

Click here to see Installation Video!

If the default example not added to your software isn’t functioning how it should, please report a bug here https://keyauth.cc/app/?page=forms

However, we do NOT provide support for adding KeyAuth to your project. If you can’t figure this out you should use Google or YouTube to learn more about the programming language you want to sell a program in.

KeyAuth is licensed under Elastic License 2.0

  • You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
  • You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
  • You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.

Thank you for your compliance, we work hard on the development of KeyAuth and do not appreciate our copyright being infringed.

Please add a Cloudflare firewall rule to show challenge to users, then set challenge passage to 1 year so they don’t have to frequently complete challenge image image

What is KeyAuth?

KeyAuth is an Open source authentication system with cloud hosting plans as well. Client SDKs available for C#, C++, Python, Java, JavaScript, VB.NET, PHP, Rust, Go, Lua, Ruby, and Perl. KeyAuth has several unique features such as memory streaming, webhook function where you can send requests to API without leaking the API, discord webhook notifications, ban the user securely through the application at your discretion. Feel free to join https://t.me/keyauth if you have questions or suggestions.

KeyAuthApp instance definition

Visit https://keyauth.cc/app/ and select your application, then click on the PHP tab

It’ll provide you with the code which you should replace with in the credentials.php file.

$KeyAuthApp = new KeyAuth\api("appNameHere", "keyAuthOwnerIDHere");

Initialize application

You must call this function prior to using any other KeyAuth function. Otherwise the other KeyAuth function won’t work.

Display application information

$numKeys = $_SESSION["numUsers"]; $numUsers = $_SESSION["numKeys"]; $numOnlineUsers = $_SESSION["numOnlineUsers"]; $customerPanelLink = $_SESSION["customerPanelLink"];

Login with username/password

if ($KeyAuthApp->login("userNameHere", "passWordHere")) < // send user to dashboard or wherever you prefer >

Register with username/password/key

if ($KeyAuthApp->register("userNameHere", "passWordHere", "licenseKeyHere")) < // send user to dashboard or wherever you prefer >

Upgrade user username/key

Used so the user can add extra time to their account by claiming new key.

Warning No password is needed to upgrade account. So, unlike login, register, and license functions — you should not log user in after successful upgrade.

if ($KeyAuthApp->upgrade("userNameHere", "licenseKeyHere")) < // don't login, upgrade function is not for authentication, it's simply for redeeming keys // make the user login with their username and password now. >

Login with just license key

Users can use this function if their license key has never been used before, and if it has been used before. So if you plan to just allow users to use keys, you can remove the login and register functions from your code.

if ($KeyAuthApp->license("licenseKeyHere")) < // send user to dashboard or wherever you prefer >

Show information for current logged-in user.

$username = $_SESSION["user_data"]["username"]; $subscriptions = $_SESSION["user_data"]["subscriptions"]; $subscription = $_SESSION["user_data"]["subscriptions"][0]->subscription; $expiry = $_SESSION["user_data"]["subscriptions"][0]->expiry; for ($i = 0; $i < count($subscriptions); $i++) < echo "#" . $i + 1 . " Subscription: " . $subscriptions[$i]->subscription . " - Subscription Expires: " . ""; >

Check subscription name of user

If you want to wall off parts of your app to only certain users, you can have multiple subscriptions with different names. Then, when you create licenses that correspond to the level of that subscription, users who use those licenses will get a subscription with the name of the subscription that corresponds to the level of the license key they used.

if(findSubscription("default", $_SESSION["user_data"]["subscriptions"])) < // user has subscription with name "default" > else < // user does not have subscription with name "default" >

Application variables

A string that is kept on the server-side of KeyAuth. On the dashboard you can choose for each variable to be authenticated (only logged in users can access), or not authenticated (any user can access before login). These are global and static for all users, unlike User Variables which will be dicussed below this section.

//* Get Public Variable $var = $KeyAuthApp->var("varName"); echo "Variable Data: " . $var;

User Variables

User variables are strings kept on the server-side of KeyAuth. They are specific to users. They can be set on Dashboard in the Users tab, via SellerAPI, or via your loader using the code below. discord is the user variable name you fetch the user variable by. test#0001 is the variable data you get when fetching the user variable.

//* Set Up User Variable $KeyAuthApp->setvar("varName", "varData");

And here’s how you fetch the user variable:

//* Get User Variable $var = $KeyAuthApp->getvar("varName"); echo "Variable Data: " . $var;

Application Logs

Can be used to log data. Good for anti-debug alerts and maybe error debugging. If you set Discord webhook in the app settings of the Dashboard, it will send log messages to your Discord webhook rather than store them on site. It’s recommended that you set Discord webhook, as logs on site are deleted 1 month after being sent.

You can use the log function before login & after login.

//* Log Something to the KeyAuth webhook that you have set up on app settings $KeyAuthApp->log("message");

Send HTTP requests to URLs securely without leaking the URL in your application. You should definitely use if you want to send requests to SellerAPI from your application, otherwise if you don’t use you’ll be leaking your seller key to everyone. And then someone can mess up your application.

1st example is how to send request with no POST data. just a GET request to the URL. 7kR0UedlVI is the webhook ID, https://keyauth.win/api/seller/?sellerkey=sellerkeyhere&type=black is what you should put as the webhook endpoint on the dashboard. This is the part you don’t want users to see. And then you have &ip=1.1.1.1&hwid=abc in your program code which will be added to the webhook endpoint on the keyauth server and then the request will be sent.

2nd example included post data, JSON. It’s an example request to Discord webhook 7kR0UedlVI is the webhook ID, https://discord.com/api/webhooks/. is the webhook endpoint.

$result = $KeyAuthApp->webhook("7kR0UedlVI", "&ip=1.1.1.1&hwid=abc"); echo " 
Result from Webhook:
" . $result; $result = $KeyAuthApp->webhook("7kR0UedlVI", "", "\"content\": \"webhook message here\",\"embeds\": null>", "application/json"); // if Discord webhook message successful, response will be empty echo "
Result from Webhook:
" . $result;

Ban the user and blacklist their HWID and IP Address.

Function only works after login.

The reason paramater will be the ban reason displayed to the user if they try to login, and visible on the KeyAuth dashboard.

$KeyAuthApp->ban('Broke the rules');

Источник

Connecting to SFTP with PHP

If you need to connect to SFTP using PHP then the simplest approach I’ve found is to use phpseclib, a library of functions for secure communications.

The library is a Composer package so you will need to have Composer installed, then just require the package as usual:-

$ composer require phpseclib/phpseclib

The library provides what it refers to as a “pure- PHP implementation of SFTP ” and supports the most widely used versions of SFTP .

To initiate a connection a new object of SFTP is created with the address of the remote server passed to the constructor. To authenticate our SFTP connection we can pass the login credentials using SFTP::login() :-

use phpseclib\Net\SFTP; $sftp = new SFTP('www.example.com'); if (!$sftp->login('username', 'password'))

If we’ve got a private key we need to use the RSA class so that we can pass the key in place of the password to the SFTP::login() method:-

use phpseclib\Crypt\RSA; use phpseclib\Net\SFTP; $sftp = new SFTP('www.example.com'); $Key = new RSA(); // If the private key has a passphrase we set that first $Key->setPassword('passphrase'); // Next load the private key using file_gets_contents to retrieve the key $Key->loadKey(file_get_contents('path_to_private_key')); if (!$sftp->login('username', $Key))

The SFTP class provides methods for SFTP similar to those provided by PHP ’s FTP extension. For example, to get a list of files for the current directory we use nlist() (equivalent of ftp_nlist ):-

To change directory use chdir() :-

To get a file from the remote server use get() :-

$sftp->get('remote_file', 'local_file');

This saves the remote_file to local_file . If the second parameter is left empty then the method returns the contents of the remote file if successful (otherwise it returns false ).

To upload a file to the remote server use put() :-

$sftp->put('remote_file', 'contents for remote file');

There are many other methods available and can be found in the SFTP class. The class is well documented with thorough comments. The above methods should get you started though.

Hopefully you can see that phpseclib provides a simple way of working with a SFTP connection.

Источник

Читайте также:  Php namespace and class loading
Оцените статью