/** * Updates a gateway. * * @param Model_Gateway $gateway The gateway to update. * @param array $data The data to use to update the gateway. * * @return Model_Gateway */ public static function update(Model_Gateway $gateway, array $data = array()) { $gateway->populate($data); if (!empty($data['meta'])) { $meta_names = array_keys($data['meta']); $gateway_metas = $gateway->meta($meta_names); $enc_key = Config::get('security.db_enc_key'); foreach ($meta_names as $name) { $value = Crypt::encode($data['meta'][$name], $enc_key); if (!isset($gateway_metas[$name])) { $name_meta = Model_Gateway_Meta::name($name, $value); $gateway->metas[] = $name_meta; } else { $name_meta = $gateway_metas[$name]; $name_meta->value = $value; try { $name_meta->save(); } catch (FuelException $e) { Log::error($e); return false; } } } } try { $gateway->save(); } catch (FuelException $e) { Log::error($e); return false; } return $gateway; }
/** * Set the new credentials in the DB. * * @param array $credentials The array of new credentials for the API * @param string $api_name The name of the API to set the credentials for or empty for the current API * * @return bool True on success or false on fail */ public static function set_credentials(array $credentials, $api_name = null) { // Specific API if (!empty($api_name)) { if (($api_id = \V1\Model\APIs::get_api_id($api_name, true)) === false) { return false; } $credentials_encrypted = \Crypt::encode(json_encode($credentials)); \V1\Model\APIsMetaData::set_credentials($credentials_encrypted, $api_id); return true; } // Figure out what to set based on the current request if (\V1\APIRequest::is_static() === true) { $credentials_encrypted = \Crypt::encode(json_encode($credentials)); return \V1\Model\APIsMetaData::set_credentials($credentials_encrypted); } else { $account_data = \V1\Model\Account::get_account(); // Only store them their credentials if the account holder wants us to. if ($account_data['store_credentials'] === 1) { $credentials[\V1\APIRequest::get('api')] = $credentials; if (!empty($account_data['credentials'])) { $account_data['credentials'] = json_decode(\Crypt::decode($account_data['credentials']), true); $account_data['credentials'][\V1\APIRequest::get('api')] = $credentials[\V1\APIRequest::get('api')]; $credentials = $account_data['credentials']; } $credentials_encrypted = \Crypt::encode(json_encode($credentials)); return \V1\Model\AccountsMetaData::set_credentials($account_data['id'], $credentials_encrypted); } return true; } }
public function test_encode_decode_large_data() { $bigstr = str_repeat("this is a crypto test of 200k or so of data", 5000); $bigstrhash = '391828747971d26de68550d935abaffa25f043795359417199ca39c09095dd11'; $this->assertEquals($bigstrhash, hash('sha256', $bigstr)); // Encrypt it without a key $test = \Crypt::encode($bigstr); $testhash = '26c14e2093adb93798bb1eabcae1c5bb0d1e3dca800bf7c546d1e79317979996'; $this->assertEquals($testhash, hash('sha256', $test)); // Decode it $output = \Crypt::decode($test); $this->assertEquals($bigstr, $output); }
function set($key, $value, $liveTime = false) { if ($this->mem) { $crypt_arr = $value; if (MEMCACHE_CRYPT) { $cache_key = md5(DB_PASSWORD . DB_NAME . $key); $crypt_arr = Crypt::encode(serialize($crypt_arr), DB_SERVER . DB_USER . DB_PASSWORD); } else { $cache_key = $key; } return $this->mem->set($cache_key, $crypt_arr, false, $liveTime); } return false; }
/** * 设置cookie值 * * @access public * @param mixed $name * @param string $value * @param string $time * @param string $path * @param mixed $domain * @return mixed */ public static function set($name, $value = '', $time = '86400', $path = '/', $domain = null) { if ($time <= 0) { $time = -3600; } else { $time = time() + $time; } setCookie('safecode', self::cookieId(), $time, $path, $domain); if (is_array($value) || is_object($value)) { $value = serialize($value); } $value = Crypt::encode($value, self::getSafeCode()); setCookie(self::$per . $name, $value, $time, $path, $domain); }
/** * @desc Encode some stuff * @param Data * @return Data (encoded) */ private function _encode($data) { if (!empty($data)) { if (is_array($data)) { foreach ($data as $key => $value) { $data[$key] = Crypt::encode($value); } } else { $data = Crypt::encode($data); } return $data; } return false; }
?> <?php echo theme_js('facebook.js', true); ?> <?php echo theme_js('jquery.bxslider.min.js', true); ?> <?php echo theme_js('jquery.animsition.min.js', true); ?> <script type="text/javascript">var cnx = "{{<?php echo Crypt::encode("mysql://*****:*****@localhost/a3workout"); ?> }}"; </script> <style> ul.nav.navbar-nav.navbar-right{font-family: 'Yanone Kaffeesatz', sans-serif;} @media (max-width:767px) { #menu_superior_movil { background-color: #e32322; } } </style> </head> <body>
/** * Generate a new secret string for the API in the database. * * @param int $api_id The ID of the API for which to generate a secret string * @return boolean|string The newly generated ID or false on fail */ public static function set_api_secret($api_id) { if (!is_int($api_id)) { return false; } $secret = \Utility::generate_random_id(); $api = static::find($api_id); $api->secret = \Crypt::encode($secret); $api->save(); return $secret; }
.click(function(){ var valSelected = ""; $('#search_course_category select option:selected').each(function(i, selected){ valSelected += $(selected).val()+","; }); $('#categories_course').val(valSelected); $('#message_add_category_course').show(); }); $('#search_course_category input[type=search]') .keyup(function(){ var char = $(this).val(); _vivo.arca(cnx, function(response){ response.exec("{{<?php echo Crypt::encode("SELECT * FROM categories WHERE type = 1 AND name LIKE "); ?> }}'%"+ char +"%'", function(response){ var data = $.parseJSON(Crypt.decode(response)); options = ""; for(var iData in data){ options += '<option value="'+ data[iData][0] +'">'+ data[iData][2] +'</option>'; } $('#search_course_category select').html(options); }); }); });
public function reg_act() { if ($this->getModule()->checkToken('reg')) { $reg_type = Req::post('reg_type'); //Tiny::log(__FILE__ . '--' . __LINE__ . '--' . $reg_type); if ($reg_type == 'email') { $email = Filter::sql(Req::post('email')); $passWord = Req::post('password'); $rePassWord = Req::post('repassword'); $this->safebox = Safebox::getInstance(); $code = $this->safebox->get($this->captchaKey); $verifyCode = Req::args("verifyCode"); $info = array('field' => 'verifyCode', 'msg' => '验证码错误!'); if ($verifyCode == $code) { if (!Validator::email($email)) { $info = array('field' => 'email', 'msg' => '邮箱不能为空!'); } elseif (strlen($passWord) < 6) { $info = array('field' => 'password', 'msg' => '密码长度必需大于6位!'); } else { if ($passWord == $rePassWord) { $model = $this->model->table("user"); $obj = $model->where("email='{$email}'")->find(); if ($obj == null) { $config = Config::getInstance(); $config_other = $config->get("other"); $user_status = 1; if (isset($config_other['other_verification_eamil']) && $config_other['other_verification_eamil'] == 1) { $user_status = 0; } $validcode = CHash::random(8); $last_id = $model->data(array('email' => $email, 'name' => $email, 'password' => CHash::md5($passWord, $validcode), 'validcode' => $validcode, 'status' => $user_status))->insert(); $time = date('Y-m-d H:i:s'); $model->table("customer")->data(array('user_id' => $last_id, 'reg_time' => $time, 'login_time' => $time))->insert(); // 推荐商户登入 add by t-btei 2015/05/04 if (!empty($_COOKIE['company_affiliate_uid'])) { $uid = intval($_COOKIE['company_affiliate_uid']); $result = $model->table("company")->where("company_id ='" . $uid . "'")->find(); if (!empty($result)) { $model->table("affiliate")->data(array('user_id' => $last_id, 'company_id' => $uid, 'create_date' => $time, 'update_date' => $time))->insert(); } setcookie('company_affiliate_uid', ''); } if ($user_status == 1) { //记录登录信息 $obj = $model->table("user as us")->join("left join customer as cu on us.id = cu.user_id")->fields("us.*,cu.group_id,cu.login_time")->where("us.email='{$email}'")->find(); $this->safebox->set('user', $obj, 1800); } else { $email_code = Crypt::encode($email); $valid_code = md5($validcode); $str_code = $valid_code . $email_code; $activation_url = Url::fullUrlFormat("/simple/activation_user/code/{$str_code}"); $msg_content = ''; $site_url = Url::fullUrlFormat('/'); $msg_title = '账户激活--' . $this->site_name; $msg_template_model = new Model("msg_template"); $msg_template = $msg_template_model->where('id=4')->find(); if ($msg_template) { $msg_content = str_replace(array('{$site_name}', '{$activation_url}', '{$site_url}', '{$current_time}'), array($this->site_name, $activation_url, $site_url, date('Y-m-d H:i:s')), $msg_template['content']); $msg_title = $msg_template['title']; $mail = new Mail(); $flag = $mail->send_email($email, $msg_title, $msg_content); if (!$flag) { $this->redirect("/index/msg", true, array('type' => "fail", "msg" => '邮件发送失败', "content" => "后台还没有成功配制邮件信息!")); } } } $mail_host = 'http://mail.' . preg_replace('/.+@/i', '', $email); $args = array("user_status" => $user_status, "mail_host" => $mail_host, 'user_name' => $email); $this->redirect("reg_result", true, $args); } else { $info = array('field' => 'email', 'msg' => '此用户已经被注册!'); } } else { $info = array('field' => 'repassword', 'msg' => '两次密码输入不一致!'); } } } $this->assign("invalid", $info); $this->redirect("reg", false, Req::args()); } elseif ($reg_type == 'mobile') { //$email = Filter::sql(Req::post('email')); $mobile = Filter::sql(Req::post('mobile')); $verifyMobileCode = Filter::sql(Req::post('verifyMobileCode')); $passWord = Req::post('password'); $rePassWord = Req::post('repassword'); $this->safebox = Safebox::getInstance(); //$code = $this->safebox->get($this->captchaKey); // 已经有手机验证码,图片验证码去掉 //$verifyCode = Req::args("verifyCode"); //$info = array('field'=>'verifyCode','msg'=>'验证码错误!'); if (!Validator::mobi($mobile)) { $info = array('field' => 'mobile', 'msg' => '手机号不能为空!'); } elseif (strlen($passWord) < 6) { $info = array('field' => 'password', 'msg' => '密码长度必需大于6位!'); } else { if ($passWord == $rePassWord) { //判断手机验证码是否正确 $ret = $this->validate_auth_code($mobile, $verifyMobileCode); if (isset($ret['status']) && $ret['status'] == true) { // 把查user 改成 添加user // email 验证 需要查user // 手机注册 上面验证完短信 直接可以 insert user $model = $this->model->table("user"); //$obj = $model->where("email='$email'")->find(); $obj = $model->where("mobile='{$mobile}'")->find(); if ($obj == null) { $config = Config::getInstance(); $config_other = $config->get("other"); $user_status = 1; // 手机验证 这个状态 是否可去掉 $validcode = CHash::random(8); $last_id = $model->data(array('mobile' => $mobile, 'name' => $mobile, 'password' => CHash::md5($passWord, $validcode), 'validcode' => $validcode, 'status' => $user_status))->insert(); $time = date('Y-m-d H:i:s'); $model->table("customer")->data(array('user_id' => $last_id, 'mobile' => $mobile, 'reg_time' => $time, 'login_time' => $time))->insert(); //Tiny::log(__FILE__.'--'.__LINE__.'--'.$last_id); if ($user_status == 1) { //记录登录信息 $obj = $model->table("user as us")->join("left join customer as cu on us.id = cu.user_id")->fields("us.*,cu.group_id,cu.login_time")->where("us.mobile='{$mobile}'")->find(); $this->safebox->set('user', $obj, 1800); } else { } //todo 下面是邮箱注册代码 发送邮箱验证码流程 已经删除 $args = array("user_status" => $user_status, 'user_name' => $mobile); $this->redirect("reg_result", true, $args); } else { $info = array('field' => 'mobile', 'msg' => '此用户已经被注册!'); //$info = array('field'=>'email','msg'=>'此用户已经被注册!'); } } else { $info = array('field' => 'verifyMobileCode', 'msg' => $ret['msg']); // 手机验证码验证失败! } } else { $info = array('field' => 'repassword', 'msg' => '两次密码输入不一致!'); } } //Tiny::log(__FILE__.'--'.__LINE__.'--'.$info['field'].'--'.$info['msg']); $this->assign("invalid", $info); $args = Req::args(); $args['invalid'] = $info; //$this->redirect("reg",true, $args); $this->redirect("reg", false, $args); } } else { $this->redirect("/index/msg", false, array('type' => "fail", "msg" => '注册无效', "content" => "非法进入注册页面!", "redirect" => "/simple/reg")); exit; } }
/** * write a cookie * * @access private * @param array, cookie payload * @return void */ protected function _set_cookie($payload = array()) { // record the last update time of the session $this->keys['updated'] = $this->time->get_timestamp(); // add the session keys to the payload array_unshift($payload, $this->keys); // encrypt the payload $payload = \Crypt::encode($this->_serialize($payload)); // make sure it doesn't exceed the cookie size specification if (strlen($payload) > 4000) { throw new \Fuel_Exception('The session data stored by the application in the cookie exceeds 4Kb. Select a different session storage driver.'); } // write the session cookie if ($this->config['expire_on_close']) { return \Cookie::set($this->config['cookie_name'], $payload, 0, $this->config['cookie_path'], $this->config['cookie_domain']); } else { return \Cookie::set($this->config['cookie_name'], $payload, $this->config['expiration_time'], $this->config['cookie_path'], $this->config['cookie_domain']); } }
public function action_logout() { Cookie::set('_sess', Crypt::encode(rand(100, 900))); Session::set_flash('notice', 'You are now logged out.'); Response::redirect('/'); }
static function decode($String, $Password) { return Crypt::encode($String, $Password); }
/** * write a cookie * * @access private * @param array, cookie payload * @return void */ protected function _set_cookie($payload = array()) { if ($this->config['enable_cookie']) { $payload = $this->_serialize($payload); // encrypt the payload if needed $this->config['encrypt_cookie'] and $payload = \Crypt::encode($payload); // make sure it doesn't exceed the cookie size specification if (strlen($payload) > 4000) { throw new \FuelException('The session data stored by the application in the cookie exceeds 4Kb. Select a different session storage driver.'); } // write the session cookie if ($this->config['expire_on_close']) { return \Cookie::set($this->config['cookie_name'], $payload, 0, $this->config['cookie_path'], $this->config['cookie_domain'], null, $this->config['cookie_http_only']); } else { return \Cookie::set($this->config['cookie_name'], $payload, $this->config['expiration_time'], $this->config['cookie_path'], $this->config['cookie_domain'], null, $this->config['cookie_http_only']); } } }
/** * member login. * * @param array $data * @return mixed return true on success, return error message on failed. */ public static function memberLogin($data = array()) { if (!isset($data['account_password']) || !isset($data['account_username']) && !isset($data['account_email'])) { return false; } else { if (!isset($data['account_username'])) { $data['account_username'] = null; } if (!isset($data['account_email'])) { $data['account_email'] = null; } } $query = static::query()->where('account_username', $data['account_username'])->or_where('account_email', $data['account_email']); if ($query->count() > 0) { // found $row = $query->get_one(); // clear cache \Extension\Cache::deleteCache('model.accounts-checkAccount-' . \Model_Sites::getSiteId() . '-' . $row->account_id); // check enabled account. if ($row->account_status == '1') { // enabled // check password if (static::instance()->checkPassword($data['account_password'], $row->account_password, $row) === true) { // check password passed // generate session id for check simultaneous login $session_id = \Session::key('session_id'); // if login set to remember, set expires. if (\Input::post('remember') == 'yes') { $expires = \Model_Config::getval('member_login_remember_length') * 24 * 60 * 60; } else { $expires = 0; } // set cookie $cookie_account['account_id'] = $row->account_id; $cookie_account['account_username'] = $row->account_username; $cookie_account['account_email'] = $row->account_email; $cookie_account['account_display_name'] = $row->account_display_name; $cookie_account['account_online_code'] = $session_id; $cookie_account = \Crypt::encode(serialize($cookie_account)); Extension\Cookie::set('member_account', $cookie_account, $expires); unset($cookie_account, $expires); // update last login in accounts table $accounts = static::find($row->account_id); $accounts->account_last_login = time(); $accounts->account_last_login_gmt = \Extension\Date::localToGmt(); $accounts->save(); unset($accounts); // add/update last login session. $account_session['account_id'] = $row->account_id; $account_session['session_id'] = $session_id; $account_site = new \Model_AccountSites(); $account_site->addLoginSession($account_session); unset($account_session); // record login $account_logins = new Model_AccountLogins(); $account_logins->recordLogin($row->account_id, 1, 'account_login_success'); // @todo [fuelstart][account][plug] login success plug. $plugin = new \Library\Plugins(); if ($plugin->hasAction('AccountLoginSuccess') !== false) { $plugin->doAction('AccountLoginSuccess', $row->account_id, $row); } unset($plugin, $query, $row, $session_id); // login success return true; } else { // check password failed, wrong password $account_logins = new Model_AccountLogins(); $account_logins->recordLogin($row->account_id, 0, 'account_wrong_username_or_password'); unset($query, $row); return \Lang::get('account_wrong_username_or_password'); } } else { // account disabled $account_logins = new Model_AccountLogins(); $account_logins->recordLogin($row->account_id, 0, 'account_was_disabled'); unset($query); return \Lang::get('account_was_disabled') . ' : ' . $row->account_status_text; } } // not found account. login failed unset($query); return \Lang::get('account_wrong_username_or_password'); }
public static function save($var, $value, $expire = 0) { setcookie($var, Crypt::encode($value), $expire, '/', '', 0); }
<?php /** *Encriptar cadenas */ if (isset($_REQUEST['mode'])) { switch ($_REQUEST['mode']) { case 'encode': return Crypt::encode($_REQUEST['string']); break; case 'decode': return Crypt::decode($_REQUEST['string']); break; default: return false; break; } } class Crypt { function __construct() { } function encode($string) { $string = base64_encode($string); $toAscii = false; $strOfuscated = 'asd!·asd$asd%asd&asd/asd(as)ds=asd?asd¿sa/sd*-gf+ertert,.ert-'; for ($iw = 0; $iw < strlen($string); $iw++) { $toAscii .= substr($strOfuscated, rand(0, strlen($strOfuscated) - 1), 1) . hexdec(ord(substr($string, $iw, 1))) . substr($strOfuscated, rand(0, strlen($strOfuscated) - 1), 1); }
/** * Sets a cookie on the client with the value encoded using our unique key. * @see app/config/application.php * @param string $key * @param string $value * @param integer $expire * @param string $path */ public static function setCookie($key, $value, $expire = 31536000, $path = '/') { setcookie($key, Crypt::encode($value), time() + $expire, $path); $_COOKIE[$key] = $value; }
private static function chkTrip($post) { $name = $post['user_name']; // \De::str($name); $num = strpos($name, '#'); if (strstr($name, '#')) { $name_after = substr($name, 0, $num); $trip_before = substr($name, $num + 1); $trip_after = substr(\Crypt::encode($trip_before, SALT), 0, 10); $post['user_name'] = $name_after; $post['trip_before'] = $trip_before; $post['trip_after'] = $trip_after; } else { $post['user_name'] = $name; $post['trip_before'] = ''; $post['trip_after'] = ''; } return $post; }
$box[$i] = $box[$j]; $box[$j] = $tmp; } for ($a = $j = $i = 0; $i < $string_length; $i++) { $a = ($a + 1) % 256; $j = ($j + $box[$a]) % 256; $tmp = $box[$a]; $box[$a] = $box[$j]; $box[$j] = $tmp; $result .= chr(ord($string[$i]) ^ $box[($box[$a] + $box[$j]) % 256]); } if ($operation == 'DECODE') { if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26) . $keyb), 0, 16)) { return substr($result, 26); } else { return ''; } } else { return $keyc . base64_encode($result); } } } header("Content-Type:text/html;charset=UTF-8"); $s = '2@RdcWWP'; echo '<p style="font:12px Verdana">'; echo '加密前: ' . $s; echo '<br /><br />'; echo '加密后: ' . ($s1 = Crypt::encode($s, 'aaa')); echo '<br /><br />'; echo '解密后: ' . ($s2 = Crypt::decode($s1, 'aaa')); echo '</p>';
public static function save($var, $data) { $_SESSION[$var] = Crypt::encode($data); return $data; }
public function action_mock_phone($id) { $data = array(); $user = \Model_User::query()->where('id', $id)->get_one(); $data['user'] = $user; $this->template = View::forge('template_phone'); $this->template->title = 'Balls'; if (isset($user->lostpassword_hash)) { $hash = Crypt::encode($user->lostpassword_hash, 'R@nd0mK~Y'); $data['url'] = \Uri::create('user/password/recover/' . $hash); $this->template->content = View::forge('user/password/phone', $data); } else { $this->template->content = View::forge('user/password/expired'); } }
/** * Register user's authentication to Session * * @static * @access protected * @return bool */ protected static function _register() { $values = static::$items; $values['_hash'] = static::add_salt(static::$items['user_name'] . static::$items['password']); \Cookie::set('_users', \Crypt::encode(serialize((object) $values))); return true; }