# Key Check Library

{% hint style="info" %}
In most situations, manual key validation isn’t necessary because protected scripts already handle authorization and will automatically block access if a key is invalid.\
However, if you want to verify a key before any access checks are triggered, which kicks the user out of the game, you can use this library we provide.
{% endhint %}

{% hint style="warning" %}
Using this key check library, will assign the key with the current HWID, if it is unassigned.
{% endhint %}

{% hint style="danger" %}
This SDK is not made to be secure, this is meant for custom key system prechecks. Your actual script should always use the luaprot loader!
{% endhint %}

The best case you would use this, would be before the actual luaprot loader being executed (ex. Key System GUI), as they otherwise get kicked for invalid key, blacklisted, etc.\
\
**Example Usage:**

```lua
local sdk = loadstring(game:HttpGet("https://sdk.luaprot.net/"))()

-- set the script id
sdk.scriptId = "53587481141279449402"

-- checking key
local result = sdk:checkKey("d97b328732f76c31a55ba92d")

if result.status == "VALID" then
    -- key is valid, do something with the returned data!
    
    print(result.data.keyExecutions) -- total key executions if key was found
    print(result.data.scriptExecutions) -- total script executions
    print(result.data.note) -- key note if it exists
    print(result.data.expire) -- expiration in seconds from the current time
    print(result.data.premium) -- if advertisement key or no key, this will return false
    print(result.data.discordId) -- discord id if linked
    print(result.data.discordUsername) -- discord username if discord is linked and data was found
    
    -- alternatively we can load the script; but you also can use the normal loader
    sdk:loadScript()
else
    -- key check failed
    warn(("[%s] :: %s"):format(result.status, result.message))
end
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.luaprot.net/luaprot/macro-documentation/key-check-library.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
