Exemplo n.º 1
0
 /**
  * Reset password
  * send an email with new credentials
  *
  * @param   integer	$id User ID
  * @param   string	$md5 Encrypted verification code
  * @return  void
  */
 public function reset($id, $md5)
 {
     $mod = new X4Auth_model('users');
     $user = $mod->get_by_id($id, 'users', 'last_in, password, mail, username');
     if ($user) {
         // user exists
         if (md5($user->last_in . SITE . $user->password) == $md5 && time() - strtotime($user->last_in) < 604800) {
             $new_pwd = X4Text_helper::random_string(6);
             $result = $mod->reset($user->mail, $new_pwd);
             if ($result) {
                 // load dictionary
                 $this->dict->get_wordarray(array('login', 'pwd_recovery'));
                 $src = array('XXXUSERNAMEXXX', 'XXXPASSWORDXXX');
                 $rpl = array($user->username, $new_pwd);
                 $view = new X4View_core(X4Utils_helper::set_tpl('mail'));
                 $view->subject = SERVICE . ' - ' . _RECOVERY_SUBJECT;
                 $view->message = str_replace($src, $rpl, _RECOVERY_BODY_RESET);
                 // build msg
                 $body = $view->__toString();
                 $msg = mb_convert_encoding($body, 'ISO-8859-1', 'auto');
                 // recipients
                 $to = array(array('mail' => $user->mail, 'name' => $user->username));
                 $check = X4Mailer_helper::mailto(MAIL, true, $view->subject, $msg, $to, array());
                 X4Utils_helper::set_msg($check, _RECOVERY_PWD_OK, _MSG_ERROR);
                 header('Location: ' . BASE_URL . 'login/recovery');
                 die;
             }
             // log
             if (LOGS) {
                 $mod->logger($user->id, 1, 'users', 'recovery password completed for ' . $user->mail);
             }
         } else {
             if (LOGS) {
                 $mod->logger($user->id, 1, 'users', 'recovery password failed for ' . $user->mail);
             }
         }
     } else {
         if (LOGS) {
             $mod->logger($user->id, 1, 'users', 'recovery password attempt from unknown id ' . $id);
         }
     }
     X4Utils_helper::set_msg(false, '', _RECOVERY_PWD_ERROR);
     header('Location: ' . BASE_URL . 'login/recovery');
     die;
 }
Exemplo n.º 2
0
 /**
  * Create captcha image
  *
  * @static
  * @param integer	$length The length of captcha
  * @param string	$font	The font to use
  * @param array		$bg	Background color
  * @return image
  */
 public static function captcha($length = 5, $font = 'espek___.ttf', $bg = array(255, 255, 255))
 {
     $_SESSION['captcha'] = X4Text_helper::random_string($length);
     // create image
     $size_x = 200;
     $size_y = 70;
     $img = imagecreatetruecolor($size_x, $size_y);
     $backgroung = imagecolorallocate($img, $bg[0], $bg[1], $bg[2]);
     // alpha channel for opacity
     //$color[] = imagecolorallocatealpha($img,110,110,110,50);
     $color[] = imagecolorallocatealpha($img, 68, 136, 0, 50);
     $color[] = imagecolorallocatealpha($img, 187, 0, 102, 60);
     $color[] = imagecolorallocatealpha($img, 54, 195, 255, 60);
     $color[] = imagecolorallocatealpha($img, 254, 135, 2, 60);
     $color[] = imagecolorallocatealpha($img, 170, 2, 2, 60);
     $color[] = imagecolorallocatealpha($img, 255, 193, 7, 60);
     shuffle($color);
     $colors = sizeof($color);
     // background
     imagefilledrectangle($img, 0, 0, $size_x - 1, $size_y - 1, $backgroung);
     $code = str_split($_SESSION['captcha']);
     // captcha
     foreach ($code as $k => $v) {
         // character
         imagettftext($img, 50, -3 + rand(0, 15), ($k + 0.8) * 24, 58 + rand(-8, 8), $color[$k % $colors], $_SERVER['DOCUMENT_ROOT'] . ROOT . 'files/files/' . $font, $v);
     }
     // output
     header('Content-Type: image/png');
     imagepng($img, null, 0, null);
     imagedestroy($img);
     die;
 }