Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Teste {
- const EU = "<b>Disse ele:</b>n";
- public function eu(){
- return self::EU . $this->ele();
- }
- private function ele(){
- return 'Pertenço a 3º pessoa';
- }
- }
- $teste = new Teste();
- print $teste->eu();
- ?>
- class Teste1 {
- const EU = "<b>Disse ele:</b>n";
- public static function eu(){
- return self::EU . $this->ele();
- }
- private function ele(){
- return 'Pertenço à 3º pessoa';
- }
- }
- print Teste1::eu();
- <?php
- class Teste1 {
- static $instance;
- const EU = "<b>Disse ele:</b>n";
- public static function get(){
- if(empty(self::$instance)):
- self::$instance = new Teste1();
- endif;
- return self::$instance;
- }
- public static function eu(){
- return self::EU . self::$instance->ele();
- }
- private function ele(){
- return 'Pertenço à 3º pessoa';
- }
- }
- print Teste1::get()->eu();
- ?>
- <?php
- class Hash {
- static $hash;
- const COST = "$2y$10$";
- public static function hash_create($password){
- return crypt($password, $this->salt(self::COST)); # <--- $this
- }
- public static function hash_verify($password, $db_hash){
- $hash = crypt($password, $db_hash);
- return $this->are_equal($hash, $db_hash); # <--- $this
- }
- // métodos projectados apenas para uso interno
- private function random(){
- return md5(uniqid(), true);
- }
- private function fix_random($random){
- $encode = base64_encode($random);
- return str_replace("+", ".", $encode);
- }
- private function half_salt($size=null){
- $size = empty($size) ? 22 : $size;
- return substr($this->fix_random($this->random()), 0, $size);
- }
- private function salt($cost){
- return $cost.$this->half_salt();
- }
- private function are_equal($x, $y){
- if($x === $y):
- return true;
- else:
- return false;
- endif;
- }
- }
- ## 3º Método - PRETENDIDO (nada será executado) ##
- print Hash::hash_create('password');
- print "<br/>";
- $db_hash = Hash::hash_create('password');
- var_dump(Hash::hash_verify('password', $db_hash)); # (null);
- ?>
- <?php
- class Hash {
- static $hash;
- const COST = "$2y$10$";
- # 1º notação
- public function create($password){
- return crypt($password, $this->salt(self::COST));
- }
- public function verify($password, $db_hash){
- $hash = crypt($password, $db_hash);
- return $this->are_equal($hash, $db_hash);
- }
- // métodos projectados apenas para uso interno
- private function random(){
- return md5(uniqid(), true);
- }
- private function fix_random($random){
- $encode = base64_encode($random);
- return str_replace("+", ".", $encode);
- }
- private function half_salt($size=null){
- $size = empty($size) ? 22 : $size;
- return substr($this->fix_random($this->random()), 0, $size);
- }
- private function salt($cost){
- return $cost.$this->half_salt();
- }
- private function are_equal($x, $y){
- if($x === $y):
- return true;
- else:
- return false;
- endif;
- }
- }
- ## 1º Método - NORMAL ##
- $hash = new Hash(); # <---
- print $hash->create('password');
- print "<br/>";
- $db_hash = $hash->create('password');
- var_dump($hash->verify('password', $db_hash)); # (true);
- ?>
- <?php
- class Hash {
- static $hash;
- const COST = "$2y$10$";
- public static function instance(){
- if(empty(self::$hash)){
- self::$hash = $self = new Hash();
- }
- return self::$hash;
- }
- # 2º notação
- public static function hash_create($password){
- return crypt($password, self::$hash->salt(self::COST));
- }
- public static function hash_verify($password, $db_hash){
- $hash = crypt($password, $db_hash);
- return self::$hash->are_equal($hash, $db_hash);
- }
- // métodos projectados apenas para uso interno
- private function random(){
- return md5(uniqid(), true);
- }
- private function fix_random($random){
- $encode = base64_encode($random);
- return str_replace("+", ".", $encode);
- }
- private function half_salt($size=null){
- $size = empty($size) ? 22 : $size;
- return substr($this->fix_random($this->random()), 0, $size);
- }
- private function salt($cost){
- return $cost.$this->half_salt();
- }
- private function are_equal($x, $y){
- if($x === $y):
- return true;
- else:
- return false;
- endif;
- }
- }
- ## 2º Método - HACK ##
- print Hash::instance()->hash_create('password');
- print "<br/>";
- $db_hash = Hash::hash_create('password');
- var_dump(Hash::hash_verify('password', $db_hash)); # (true);
- ?>
- class Teste {
- const EU = "<b>Disse ele:</b>n";
- public static function eu() {
- return self::EU . static::ele();
- }
- private static function ele(){
- return 'Pertenço a 3º pessoa';
- }
- }
- Teste::eu();
- class Usuario
- {
- public funciton setNome($nome) { $this->nome = $nome; return $this; }
- public function getNome(){ return $this->nome; }
- }
- class UsuarioFacade{
- public static function __callStatic($method, $arguments)
- {
- return call_user_func_array(array(new Usuario, $method), $arguments);
- }
- }
- UsuarioFacade::setNome('wallace')->getNome(); // Imprime: wallace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement