Skip to content

Commit 7e6a743

Browse files
author
Tinsh
committed
chore(*): add modules and system
1 parent 342589e commit 7e6a743

File tree

681 files changed

+71596
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

681 files changed

+71596
-0
lines changed

modules/auth/.travis.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
sudo: false
2+
3+
language: php
4+
5+
# Only build the main develop/master branches - feature branches will be covered by PRs
6+
branches:
7+
only:
8+
- /^[0-9\.]+\/(develop|master)$/
9+
10+
cache:
11+
directories:
12+
- $HOME/.composer/cache/files
13+
14+
php:
15+
- 5.3
16+
- 5.4
17+
- 5.5
18+
- 5.6
19+
- 7.0
20+
- hhvm
21+
22+
matrix:
23+
include:
24+
- php: 5.3
25+
env: 'COMPOSER_PHPUNIT="lowest"'
26+
27+
before_script:
28+
- composer self-update
29+
- composer install --prefer-dist --no-interaction
30+
- if [ "$COMPOSER_PHPUNIT" = "lowest" ]; then composer update --prefer-lowest --with-dependencies --prefer-dist --no-interaction phpunit/phpunit; fi;
31+
- vendor/bin/koharness
32+
33+
script:
34+
- cd /tmp/koharness && ./vendor/bin/phpunit --bootstrap=modules/unittest/bootstrap.php modules/unittest/tests.php
35+
36+
notifications:
37+
email: false

modules/auth/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Kohana auth module
2+
---
3+
| ver | Stable | Develop |
4+
|-------|------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|
5+
| 3.3.x | [![Build Status - 3.3/master](https://travis-ci.org/kohana/auth.svg?branch=3.3%2Fmaster)](https://travis-ci.org/kohana/auth) | [![Build Status - 3.3/develop](https://travis-ci.org/kohana/auth.svg?branch=3.3%2Fdevelop)](https://travis-ci.org/kohana/auth) |
6+
| 3.4.x | [![Build Status - 3.4/master](https://travis-ci.org/kohana/auth.svg?branch=3.4%2Fmaster)](https://travis-ci.org/kohana/auth) | [![Build Status - 3.4/develop](https://travis-ci.org/kohana/auth.svg?branch=3.4%2Fdevelop)](https://travis-ci.org/kohana/auth) |
7+
8+
I've forked the main Auth module because there were some fundamental flaws with it:
9+
10+
1. It's trivial to [bruteforce](http://dev.kohanaframework.org/issues/3163) publicly hidden salt hashes.
11+
- I've fixed this by switching the password hashing algorithm to the more secure secret-key based hash_hmac method.
12+
2. ORM drivers were included.
13+
- I've fixed this by simply removing them. They cause confusion with new users because they think that Auth requires ORM. The only driver currently provided by default is the file driver.
14+
3. Auth::get_user()'s api is inconsistent because it returns different data types.
15+
- I've fixed this by returning an empty user model by default. You can override what gets returned (if you've changed your user model class name for instance) by overloading the get_user() method in your application.
16+
17+
These changes should be merged into the mainline branch eventually, but they completely break the API, so likely won't be done until 3.1.

modules/auth/classes/Auth.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php defined('SYSPATH') OR die('No direct access allowed.');
2+
3+
abstract class Auth extends Kohana_Auth { }

modules/auth/classes/Auth/File.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php defined('SYSPATH') OR die('No direct access allowed.');
2+
3+
class Auth_File extends Kohana_Auth_File { }
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
<?php defined('SYSPATH') OR die('No direct access allowed.');
2+
/**
3+
* User authorization library. Handles user login and logout, as well as secure
4+
* password hashing.
5+
*
6+
* @package Kohana/Auth
7+
* @author Kohana Team
8+
* @copyright (c) 2007-2012 Kohana Team
9+
* @license http://kohanaframework.org/license
10+
*/
11+
abstract class Kohana_Auth {
12+
13+
// Auth instances
14+
protected static $_instance;
15+
16+
/**
17+
* Singleton pattern
18+
*
19+
* @return Auth
20+
*/
21+
public static function instance()
22+
{
23+
if ( ! isset(Auth::$_instance))
24+
{
25+
// Load the configuration for this type
26+
$config = Kohana::$config->load('auth');
27+
28+
if ( ! $type = $config->get('driver'))
29+
{
30+
$type = 'file';
31+
}
32+
33+
// Set the session class name
34+
$class = 'Auth_'.ucfirst($type);
35+
36+
// Create a new session instance
37+
Auth::$_instance = new $class($config);
38+
}
39+
40+
return Auth::$_instance;
41+
}
42+
43+
protected $_session;
44+
45+
protected $_config;
46+
47+
/**
48+
* Loads Session and configuration options.
49+
*
50+
* @param array $config Config Options
51+
* @return void
52+
*/
53+
public function __construct($config = array())
54+
{
55+
// Save the config in the object
56+
$this->_config = $config;
57+
58+
$this->_session = Session::instance($this->_config['session_type']);
59+
}
60+
61+
abstract protected function _login($username, $password, $remember);
62+
63+
abstract public function password($username);
64+
65+
abstract public function check_password($password);
66+
67+
/**
68+
* Gets the currently logged in user from the session.
69+
* Returns NULL if no user is currently logged in.
70+
*
71+
* @param mixed $default Default value to return if the user is currently not logged in.
72+
* @return mixed
73+
*/
74+
public function get_user($default = NULL)
75+
{
76+
return $this->_session->get($this->_config['session_key'], $default);
77+
}
78+
79+
/**
80+
* Attempt to log in a user by using an ORM object and plain-text password.
81+
*
82+
* @param string $username Username to log in
83+
* @param string $password Password to check against
84+
* @param boolean $remember Enable autologin
85+
* @return boolean
86+
*/
87+
public function login($username, $password, $remember = FALSE)
88+
{
89+
if (empty($password))
90+
return FALSE;
91+
92+
return $this->_login($username, $password, $remember);
93+
}
94+
95+
/**
96+
* Log out a user by removing the related session variables.
97+
*
98+
* @param boolean $destroy Completely destroy the session
99+
* @param boolean $logout_all Remove all tokens for user
100+
* @return boolean
101+
*/
102+
public function logout($destroy = FALSE, $logout_all = FALSE)
103+
{
104+
if ($destroy === TRUE)
105+
{
106+
// Destroy the session completely
107+
$this->_session->destroy();
108+
}
109+
else
110+
{
111+
// Remove the user from the session
112+
$this->_session->delete($this->_config['session_key']);
113+
114+
// Regenerate session_id
115+
$this->_session->regenerate();
116+
}
117+
118+
// Double check
119+
return ! $this->logged_in();
120+
}
121+
122+
/**
123+
* Check if there is an active session. Optionally allows checking for a
124+
* specific role.
125+
*
126+
* @param string $role role name
127+
* @return mixed
128+
*/
129+
public function logged_in($role = NULL)
130+
{
131+
return ($this->get_user() !== NULL);
132+
}
133+
134+
/**
135+
* Creates a hashed hmac password from a plaintext password. This
136+
* method is deprecated, [Auth::hash] should be used instead.
137+
*
138+
* @deprecated
139+
* @param string $password Plaintext password
140+
*/
141+
public function hash_password($password)
142+
{
143+
return $this->hash($password);
144+
}
145+
146+
/**
147+
* Perform a hmac hash, using the configured method.
148+
*
149+
* @param string $str string to hash
150+
* @return string
151+
*/
152+
public function hash($str)
153+
{
154+
if ( ! $this->_config['hash_key'])
155+
throw new Kohana_Exception('A valid hash key must be set in your auth config.');
156+
157+
return hash_hmac($this->_config['hash_method'], $str, $this->_config['hash_key']);
158+
}
159+
160+
protected function complete_login($user)
161+
{
162+
// Regenerate session_id
163+
$this->_session->regenerate();
164+
165+
// Store username in session
166+
$this->_session->set($this->_config['session_key'], $user);
167+
168+
return TRUE;
169+
}
170+
171+
} // End Auth
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php defined('SYSPATH') OR die('No direct access allowed.');
2+
/**
3+
* File Auth driver.
4+
* [!!] this Auth driver does not support roles nor autologin.
5+
*
6+
* @package Kohana/Auth
7+
* @author Kohana Team
8+
* @copyright (c) 2007-2012 Kohana Team
9+
* @license http://kohanaframework.org/license
10+
*/
11+
class Kohana_Auth_File extends Auth {
12+
13+
// User list
14+
protected $_users;
15+
16+
/**
17+
* Constructor loads the user list into the class.
18+
*/
19+
public function __construct($config = array())
20+
{
21+
parent::__construct($config);
22+
23+
// Load user list
24+
$this->_users = Arr::get($config, 'users', array());
25+
}
26+
27+
/**
28+
* Logs a user in.
29+
*
30+
* @param string $username Username
31+
* @param string $password Password
32+
* @param boolean $remember Enable autologin (not supported)
33+
* @return boolean
34+
*/
35+
protected function _login($username, $password, $remember)
36+
{
37+
if (is_string($password))
38+
{
39+
// Create a hashed password
40+
$password = $this->hash($password);
41+
}
42+
43+
if (isset($this->_users[$username]) AND $this->_users[$username] === $password)
44+
{
45+
// Complete the login
46+
return $this->complete_login($username);
47+
}
48+
49+
// Login failed
50+
return FALSE;
51+
}
52+
53+
/**
54+
* Forces a user to be logged in, without specifying a password.
55+
*
56+
* @param mixed $username Username
57+
* @return boolean
58+
*/
59+
public function force_login($username)
60+
{
61+
// Complete the login
62+
return $this->complete_login($username);
63+
}
64+
65+
/**
66+
* Get the stored password for a username.
67+
*
68+
* @param mixed $username Username
69+
* @return string
70+
*/
71+
public function password($username)
72+
{
73+
return Arr::get($this->_users, $username, FALSE);
74+
}
75+
76+
/**
77+
* Compare password with original (plain text). Works for current (logged in) user
78+
*
79+
* @param string $password Password
80+
* @return boolean
81+
*/
82+
public function check_password($password)
83+
{
84+
$username = $this->get_user();
85+
86+
if ($username === FALSE)
87+
{
88+
return FALSE;
89+
}
90+
91+
return ($password === $this->password($username));
92+
}
93+
94+
} // End Auth File

modules/auth/composer.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "kohana/auth",
3+
"type": "kohana-module",
4+
"description": "The official Kohana auth module",
5+
"homepage": "http://kohanaframework.org",
6+
"license": "BSD-3-Clause",
7+
"keywords": ["kohana", "framework", "authentication"],
8+
"authors": [
9+
{
10+
"name": "Kohana Team",
11+
"email": "team@kohanaframework.org",
12+
"homepage": "http://kohanaframework.org/team",
13+
"role": "developer"
14+
}
15+
],
16+
"support": {
17+
"issues": "http://dev.kohanaframework.org",
18+
"forum": "http://forum.kohanaframework.org",
19+
"irc": "irc://irc.freenode.net/kohana",
20+
"source": "http://github.com/kohana/core"
21+
},
22+
"require": {
23+
"composer/installers": "~1.0",
24+
"kohana/core": ">=3.3",
25+
"php": ">=5.3.3"
26+
},
27+
"require-dev": {
28+
"kohana/core": "3.3.*@dev",
29+
"kohana/unittest": "3.3.*@dev",
30+
"kohana/koharness": "*@dev"
31+
},
32+
"extra": {
33+
"branch-alias": {
34+
"dev-3.3/develop": "3.3.x-dev",
35+
"dev-3.4/develop": "3.4.x-dev"
36+
},
37+
"installer-paths": {
38+
"vendor/{$vendor}/{$name}": ["type:kohana-module"]
39+
}
40+
}
41+
}

modules/auth/config/auth.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php defined('SYSPATH') OR die('No direct access allowed.');
2+
3+
return array(
4+
5+
'driver' => 'File',
6+
'hash_method' => 'sha256',
7+
'hash_key' => NULL,
8+
'lifetime' => 1209600,
9+
'session_type' => Session::$default,
10+
'session_key' => 'auth_user',
11+
12+
// Username/password combinations for the Auth File driver
13+
'users' => array(
14+
// 'admin' => 'b3154acf3a344170077d11bdb5fff31532f679a1919e716a02',
15+
),
16+
17+
);

0 commit comments

Comments
 (0)