[2.1] Added the Apache htpasswd support for HTTP Authentication #3585

Merged
merged 1 commit into from Jan 29, 2013

Projects

None yet

2 participants

@ezimuel
Owner
ezimuel commented Jan 28, 2013

Added the Zend\Authentication\Adapter\Http\ApacheResolver component that supports the htpasswd format for authentication. The ApacheResolver uses the new Zend\Crypt\Password\Apache class to encrypt and check the passwords according with the htpasswd format.
For more detail: http://httpd.apache.org/docs/2.2/misc/password_encryptions.html

@weierophinney weierophinney commented on the diff Jan 29, 2013
...y/Zend/Authentication/Adapter/Http/ApacheResolver.php
+ /**
+ * Resolve credentials
+ *
+ *
+ *
+ * @param string $username Username
+ * @param string $realm Authentication Realm
+ * @param string $password The password to authenticate
+ * @return AuthResult
+ * @throws Exception\ExceptionInterface
+ */
+ public function resolve($username, $realm, $password = null)
+ {
+ if (empty($username)) {
+ throw new Exception\InvalidArgumentException('Username is required');
+ } elseif (!ctype_print($username) || strpos($username, ':') !== false) {
weierophinney
weierophinney Jan 29, 2013 Owner

This can be a new condition; it will always be tested if the previous condition fails anyways.

@weierophinney weierophinney commented on the diff Jan 29, 2013
...y/Zend/Authentication/Adapter/Http/ApacheResolver.php
+ }
+
+ // Plaintext password
+ if ($matchedHash === $password) {
+ return new AuthResult(AuthResult::SUCCESS, $username);
+ }
+
+ $apache = $this->getApachePassword();
+ $apache->setUserName($username);
+ if (!empty($realm)) {
+ $apache->setAuthName($realm);
+ }
+
+ if ($apache->verify($password, $matchedHash)) {
+ return new AuthResult(AuthResult::SUCCESS, $username);
+ } else {
weierophinney
weierophinney Jan 29, 2013 Owner

No need for an else here, as previous condition returns on success anyways.

@weierophinney weierophinney added a commit that referenced this pull request Jan 29, 2013
@weierophinney weierophinney [#3585] CS/logic cleanup
- Re-work conditionals to reduce nesting
- Minor whitespace changes
60799ae
@weierophinney weierophinney added a commit that referenced this pull request Jan 29, 2013
@weierophinney weierophinney Merge branch 'feature/3585' into develop
Close #3585
3dd3028
@weierophinney weierophinney merged commit d67b68c into zendframework:develop Jan 29, 2013

1 check passed

default The Travis build passed
Details
@weierophinney weierophinney added a commit to zendframework/zend-authentication that referenced this pull request May 14, 2015
@weierophinney weierophinney [zendframework/zendframework#3585] CS/logic cleanup
- Re-work conditionals to reduce nesting
- Minor whitespace changes
e8e0772
@weierophinney weierophinney added a commit to zendframework/zend-authentication that referenced this pull request May 14, 2015
@weierophinney weierophinney Merge branch 'feature/3585' into develop 1408981
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment