CMS for the late garbage.fm
at main 62 lines 1.5 kB view raw
1<?php 2 3class User extends ActiveRecord\Model { 4 public $new_password; 5 public $new_password_confirmation; 6 7 static $attr_accessible = array( 8 "username", "full_name", "twitter_username", "url", "upcoming_notes", 9 "new_password", "new_password_confirmation", 10 ); 11 12 public function set_password($password) { 13 $pw = new PasswordHash(8, FALSE); 14 $this->hashed_password = $pw->HashPassword($password); 15 } 16 17 public function password_matches($password) { 18 $pw = new PasswordHash(8, FALSE); 19 return (bool)($pw->CheckPassword($password, $this->hashed_password)); 20 } 21 22 public function validate() { 23 if (trim($this->new_password) == "") { 24 if (!$this->id) 25 $this->errors->add("new_password", "cannot be blank."); 26 } 27 else { 28 if ($this->new_password === $this->new_password_confirmation) 29 $this->set_password($this->new_password); 30 else 31 $this->errors->add("new_password", "does not match " 32 . "confirmation."); 33 } 34 } 35 36 public function get_preferred_url() { 37 if (empty($this->url)) 38 return "https://twitter.com/" . $this->twitter_username; 39 else 40 return $this->url; 41 } 42 43 public function get_new_totp() { 44 $secret = openssl_random_pseudo_bytes(40); 45 $this->totp_secret = \Base32\Base32::encode($secret); 46 return $this->totp; 47 } 48 49 public function get_totp() { 50 $totp = new \OTPHP\TOTP; 51 $totp->setLabel($this->username) 52 ->setDigits(6) 53 ->setDigest("sha1") 54 ->setInterval(30) 55 ->setIssuer(Settings::fetch()->name . " Admin") 56 ->setSecret($this->totp_secret); 57 58 return $totp; 59 } 60} 61 62?>