Overview

Namespaces

  • CJPGDK
    • PhpHttpAuth
      • Database
      • Hash
  • PHP

Classes

  • CJPGDK\PhpHttpAuth\Database\DB
  • CJPGDK\PhpHttpAuth\Database\MySQL
  • CJPGDK\PhpHttpAuth\Database\PDODB
  • CJPGDK\PhpHttpAuth\HttpAuth
  • mysqli
  • PDO

Interfaces

  • Throwable

Traits

  • CJPGDK\PhpHttpAuth\Hash\Apr1Md5
  • CJPGDK\PhpHttpAuth\Hash\Bcrypt
  • CJPGDK\PhpHttpAuth\Hash\Md5
  • CJPGDK\PhpHttpAuth\Hash\Sha

Exceptions

  • Exception
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 
<?php

namespace CJPGDK\PhpHttpAuth\Hash;

/**
 * Provides PHP methods for SHA1 hashing
 *
 * @package CJPGDK
 * @subpackage PhpHttpAuth
 * @author Christian M. Jensen <cmj@cjpg.dk>
 * @version 1.0.0
 * @since 1.0.0
 */
trait Sha
{

    /**
     * format username and password array to a '.htpasswd' line
     * @param array|string $user as array ['username' => , 'password'=>], or a user name with passwd
     * @param null|string $hashedpwd
     * @return string
     */
    public function getShaHtpasswdRow($user, $hashedpwd = null)
    {
        if (is_array($user)) {
            return "{$user['username']}:{$user['password']}";
        }
        return "{$user}:{$hashedpwd}";
    }

    /**
     * Create a user and password row.
     * @param string $user
     * @param string $pwd
     * @return array ['username' => , 'password'=>]
     */
    public function createUserSha($user, $pwd)
    {
        return array('username' => $user, 'password' => $this->getShaHash($pwd));
    }

    /**
     * Get an sha hash
     * @param string $plainpasswd
     * @return string
     */
    public function getShaHash($plainpasswd)
    {
        return "{SHA}".base64_encode(sha1($plainpasswd, TRUE));
    }

    /**
     * Validate an sha hash
     * @param string $plain
     * @param string $hash
     * @return boolean
     */
    public function matchShaHash($plain, $hash)
    {
        return $this->getShaHash($plain) === $hash;
    }
}
PhpHttpAuth API documentation generated by ApiGen