Skip to content

Commit

Permalink
apikey
Browse files Browse the repository at this point in the history
  • Loading branch information
Raeen committed Mar 16, 2021
1 parent e4aaf72 commit 0e90453
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
12 changes: 7 additions & 5 deletions .env
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
SERVERNAME = localhost
PORT = 3306
USERNAME = root
PASSWORD =
DATABASENAME = api
# Mysql Config

DB_SERVER = localhost
DB_PORT = 3306
DB_USERNAME = root
DB_PASSWORD =
DB_NAME = api
2 changes: 1 addition & 1 deletion core/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct($rootPath)
$this->response = new Response();
$this->router = new Router();
$this->file = new File();
$this->db = new DB($_ENV['SERVERNAME'] . ":" . $_ENV['PORT'], $_ENV['USERNAME'], $_ENV['PASSWORD'], $_ENV['DATABASENAME']);
$this->db = new DB($_ENV['DB_SERVER'] . ":" . $_ENV['DB_PORT'], $_ENV['DB_USERNAME'], $_ENV['DB_PASSWORD'], $_ENV['DB_NAME']);
}
public function run()
{
Expand Down
4 changes: 4 additions & 0 deletions core/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ protected function sendFile($filename)
{
return Application::$app->file->sendFile($filename);
}
protected function apikey($length = 20)
{
return Application::$app->response->apikey($length);
}
}
11 changes: 11 additions & 0 deletions core/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,15 @@ public function render(int $code, array|object $data = null, $status = null, $me
}
die(json_encode($temp));
}
public function apikey($length = 20)
{
//gen api key
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
}

0 comments on commit 0e90453

Please sign in to comment.