/** * Tests Crypt->decrypt() */ public function testDecrypt() { // Encrypt the data $encrypted = $this->crypt->encrypt(self::DATA); // Decrypt the data $decrypted = $this->crypt->decrypt($encrypted); $this->assertTrue($decrypted == self::DATA, 'Testing data decryption'); unset($encrypted, $decrypted); }
/** * Vlidate access key and find user * @param string $accessKey * @return CmfDbObject|bool - false = failed to parse access key, validate data or load user */ public static function loadFromPasswordRecoveryAccessKey($accessKey) { try { $data = \Crypt::decrypt($accessKey); } catch (DecryptException $exc) { return false; } if (empty($data)) { return false; } $data = json_decode($data, true); if (empty($data) || !is_array($data) || empty($data['account_id']) || empty($data['expires_at']) || $data['expires_at'] < time()) { return false; } /** @var CmfDbObject|ResetsPasswordsViaAccessKey $user */ $user = static::create(); $conditions = [$user->_getPkFieldName() => $data['account_id']]; foreach ($user->getAdditionalFieldsForPasswordRecoveryAccessKey() as $fieldName) { if (empty($data[$fieldName])) { return false; } $conditions[$fieldName] = $data[$fieldName]; } if (!$user->find($conditions)->exists()) { return false; } return $user; }
public static function getHomeOverview() { $db = Auth::user()->targets()->where('closed', '=', 0)->orderBy('duedate', 'DESC')->get(); $ids = array(); $data = array(); foreach ($db as $t) { $ids[] = intval($t->id); $tr = array('id' => $t->id, 'description' => Crypt::decrypt($t->description), 'amount' => floatval($t->amount), 'duedate' => $t->duedate != '0000-00-00' ? new DateTime($t->duedate) : null, 'startdate' => $t->startdate != '0000-00-00' ? new DateTime($t->startdate) : null, 'account' => intval($t->account_id), 'saved' => 0); $tr['pct'] = round($tr['saved'] / $tr['amount'] * 100, 2); $data[intval($t->id)] = $tr; } if (count($ids) > 0) { $transfers = Auth::user()->transfers()->whereIn('target_id', $ids)->where('date', '<=', Session::get('period')->format('Y-m-d'))->get(); foreach ($transfers as $t) { if ($t->account_from == $data[$t->target_id]['account']) { $data[intval($t->target_id)]['saved'] -= floatval($t->amount); } else { if ($t->account_to == $data[$t->target_id]['account']) { $data[intval($t->target_id)]['saved'] += floatval($t->amount); } } } } return $data; }
public function showAll() { $key = cacheKey('Beneficiaries', 'showAll'); if (Cache::has($key)) { $data = Cache::get($key); } else { $data = array(); $beneficiaries = Auth::user()->beneficiaries()->orderBy('id', 'ASC')->get(); // to get the avg per month we first need the number of months foreach ($beneficiaries as $ben) { $name = Crypt::decrypt($ben->name); $bene = array('id' => intval($ben->id), 'name' => $name); $now = new Carbon('now'); $thisMonth = $ben->transactions()->where(DB::Raw('DATE_FORMAT(`date`,"%m-%Y")'), '=', $now->format('m-Y'))->sum('amount'); $bene['month'] = floatval($thisMonth); $data[] = $bene; } unset($name); $name = array(); // order by alfabet // Obtain a list of columns foreach ($data as $key => $row) { $id[$key] = $row['id']; $name[$key] = $row['name']; } array_multisort($name, SORT_ASC, $id, SORT_DESC, $data); Cache::put($key, $data, 1440); } return View::make('beneficiaries.all')->with('beneficiaries', $data); }
/** * Get the validation rules that apply to the request. * * @return array */ public function rules() { switch ($this->method()) { // Create case 'POST': // rules $rules['first_name'] = "required"; $rules['last_name'] = "required"; $rules['phone'] = "required|unique:users,phone"; $rules['slug_name'] = "required|unique:users,slug"; $rules['email'] = "required|email"; $rules['password'] = "******"; $rules['group'] = "required"; return $rules; break; // Update // Update case 'PUT': // rules $rules['first_name'] = "required"; $rules['last_name'] = "required"; $rules['phone'] = "required|unique:users,phone," . \Crypt::decrypt($this->get('id')); $rules['slug_name'] = 'required|unique:users,slug,' . \Crypt::decrypt($this->get('id')); $rules['email'] = "required|email"; if ($this->has('password')) { $rules['password'] = "******"; } $rules['group'] = "required"; return $rules; break; } }
public function login(Request $request) { // dd(\Crypt::encrypt('*****@*****.**')); try { $email = \Crypt::decrypt($request->get('token')); } catch (\Exception $e) { return abort('403', 'Forbidden'); } $user = User::whereEmail($email)->first(); if (!$user) { return abort('403', 'Forbidden'); } if (!$user->account) { $b2bCompany = \DB::connection('mysql-b2b')->table('companies')->where('user_id', '=', $user->id)->first(); // $b2bCompany = false; $accountName = $b2bCompany ? $b2bCompany->company_name : $user->email; $account = new Account(); $account->ip = $request->getClientIp(); $account->name = $accountName; $account->account_key = str_random(RANDOM_KEY_LENGTH); $account->save(); $user->account_id = $account->id; $user->registered = true; $user->save(); $exists = \DB::connection('mysql')->table('users')->whereId($user->id)->count(); if (!$exists) { \DB::connection('mysql')->table('users')->insert(['id' => $user->id, 'account_id' => $user->account_id, 'created_at' => $user->created_at, 'updated_at' => $user->updated_at, 'deleted_at' => $user->deleted_at, 'first_name' => $user->first_name, 'last_name' => $user->last_name, 'phone' => $user->phone, 'username' => $user->username, 'email' => $user->email, 'password' => $user->password, 'confirmation_code' => $user->confirmation_code, 'registered' => $user->registered, 'confirmed' => $user->confirmed, 'notify_sent' => $user->notify_sent, 'notify_viewed' => $user->notify_viewed, 'notify_paid' => $user->notify_paid, 'public_id' => $user->public_id, 'force_pdfjs' => false, 'remember_token' => $user->remember_token, 'news_feed_id' => $user->news_feed_id, 'notify_approved' => $user->notify_approved, 'failed_logins' => $user->failed_logins, 'dark_mode' => $user->dark_mode, 'referral_code' => $user->referral_code]); } } \Auth::loginUsingId($user->id); return redirect('/'); }
public function getModificar($id) { $usuario = Usuario::find($id); $roles = Rol::all(); $contrasenia = Crypt::decrypt($usuario->contrasenia); return View::make("usuarios.modificar")->with("usuario", $usuario)->with("roles", $roles)->with("contrasenia", $contrasenia); }
public function showAll() { $key = cacheKey('Budgets', 'showAll'); if (Cache::has($key)) { $data = Cache::get($key); } else { $data = array(); $budgets = Auth::user()->budgets()->orderBy('date', 'DESC')->get(); foreach ($budgets as $b) { $month = new Carbon($b->date); $strMonth = $month->format('F Y'); $data[$strMonth] = isset($data[$strMonth]) ? $data[$strMonth] : array(); $budget = array('name' => Crypt::decrypt($b->name), 'amount' => floatval($b->amount), 'spent' => $b->spent(), 'overspent' => false, 'id' => intval($b->id), 'left' => 0); if ($budget['amount'] != 0) { $pct = $budget['spent'] / $budget['amount'] * 100; $budget['left'] = $budget['amount'] - $budget['spent']; if ($pct > 100) { $budget['overspent'] = true; $budget['pct'] = round($budget['amount'] / $budget['spent'] * 100, 0); } else { $budget['pct'] = round($pct); } } $data[$strMonth][] = $budget; } } return View::make('budgets.all')->with('budgets', $data); }
/** * Authenticates a user to LDAP * * @param $username * @param $password * @param bool|false $returnUser * @return bool true if the username and/or password provided are valid * false if the username and/or password provided are invalid * array of ldap_attributes if $returnUser is true */ function ldap($username, $password, $returnUser = false) { $ldaphost = Setting::getSettings()->ldap_server; $ldaprdn = Setting::getSettings()->ldap_uname; $ldappass = Crypt::decrypt(Setting::getSettings()->ldap_pword); $baseDn = Setting::getSettings()->ldap_basedn; $filterQuery = Setting::getSettings()->ldap_auth_filter_query . $username; $ldapversion = Setting::getSettings()->ldap_version; // Connecting to LDAP $connection = ldap_connect($ldaphost) or die("Could not connect to {$ldaphost}"); // Needed for AD ldap_set_option($connection, LDAP_OPT_REFERRALS, 0); ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, $ldapversion); try { if ($connection) { // binding to ldap server $ldapbind = ldap_bind($connection, $ldaprdn, $ldappass); if (($results = @ldap_search($connection, $baseDn, $filterQuery)) != false) { $entry = ldap_first_entry($connection, $results); if (($userDn = @ldap_get_dn($connection, $entry)) !== false) { if (($isBound = ldap_bind($connection, $userDn, $password)) == "true") { return $returnUser ? array_change_key_case(ldap_get_attributes($connection, $entry), CASE_LOWER) : true; } } } } } catch (Exception $e) { LOG::error($e->getMessage()); } ldap_close($connection); return false; }
public function contacto() { $mensaje = null; $userpass = User::where('email', '=', Input::get('email'))->first(); if ($userpass) { $pass = Crypt::decrypt($userpass->encry); $nombre = $userpass->username; if (isset($_POST['contacto'])) { $data = array('nombre' => $nombre, 'email' => Input::get('email'), 'pass' => $pass); $fromEmail = Input::get('email'); $fromName = Input::get('nombre'); Mail::send('emails.contacto', $data, function ($message) use($fromName, $fromEmail) { $message->to($fromEmail, $fromName); $message->from('*****@*****.**', 'administrador'); $message->subject('Nuevo Email de contacto'); }); } return Redirect::to('email')->with('status', 'ok_send'); } else { return Redirect::to('email')->with('status', 'not_send'); } //$data = Input::get('nombre'); /*foreach ($data as $key => $value) { echo $value.'<br>'; }*/ //echo $data; //var_dump($data); //return View::make('password.remind')->with('status', 'ok_create'); }
/** * Bootstrap any application services. * * @return void */ public function boot() { if ($locale = request()->cookie('locale__myProject')) { app()->setLocale(\Crypt::decrypt($locale)); } \Carbon\Carbon::setLocale(app()->getLocale()); }
public function run() { $data = $this->_context->get("data", ''); // Log::Write('【加密数据】Remote Accept:' . $data, Log::DEBUG); if ($this->_context->isPOST()) { $de_data = Crypt::decrypt($data, App::getConfig('YUC_SECURE_KEY')); // Log::Write('解析的加密数据:' . $de_data, Log::DEBUG); $post = json_decode($de_data, TRUE); if ($post != '' && is_array($post) && $post['site_key'] == md5(App::getConfig('YUC_SITE_KEY'))) { $mod = $post['mod']; $act = $post['act']; $class = 'Remote_' . $mod; if ($act == 'show' && $mod == 'Logs') { $name = $post['name']; $obj = new $class(); //self::$_string[' $name']=$name; $ret = $obj->{$act}($name); } else { $obj = new $class(); $ret = $obj->{$act}(); } Log::Write('Remote Run:' . $mod . ',' . $act . ',' . $ret, Log::DEBUG); _returnCryptAjax($ret); } else { Log::Write('安全认证错误!', Log::DEBUG); _returnCryptAjax(array('result' => 0, 'content' => '安全认证比对错误错误!')); } } else { Log::Write('远程控制错误!数据并非POST交互!', Log::DEBUG); _returnCryptAjax(array('result' => 0, 'content' => '远程控制错误!数据并非POST交互!')); } }
/** * Get the validation rules that apply to the request. * * @return array */ public function rules() { switch ($this->method()) { // Create case 'POST': // rules $rules['group_name'] = "required|unique:groups,name"; $rules['slug_name'] = "required|unique:groups,slug"; if (!count($this->permissions)) { //if permission count equal zero $rules['permissions'] = "required"; } return $rules; break; // Update // Update case 'PUT': // rules $rules['group_name'] = 'required|unique:groups,name,' . \Crypt::decrypt($this->get('id')); $rules['slug_name'] = 'required|unique:groups,slug,' . \Crypt::decrypt($this->get('id')); if (!count($this->permissions)) { //if permission count equal zero $rules['permissions'] = "required"; } return $rules; break; } }
/** * Get the cookie value * * @param string $key * @return string or null if cookie value doesn't exist */ public static function get($key) { if (!isset($_COOKIE[$key])) { return null; } return Crypt::decrypt($_COOKIE[$key], static::getKey()); }
public function updateBudgetPrediction($event) { $event->name = Crypt::decrypt($event->name); // remove all budget prediction points, if any $event->budgetpredictionpoints()->delete(); $similar = array(); // get all similar budgets from the past: $budgets = Auth::user()->budgets()->where('date', '<=', $event->date)->get(); foreach ($budgets as $budget) { $budget->name = Crypt::decrypt($budget->name); if ($budget->name == $event->name) { $similar[] = $budget->id; } } if (count($similar) > 0) { // get all transactions for these budgets: $amounts = array(); $transactions = Auth::user()->transactions()->orderBy('date', 'DESC')->where('onetime', '=', 0)->whereIn('budget_id', $similar)->get(); foreach ($transactions as $t) { $date = new Carbon($t->date); $day = intval($date->format('d')); $amounts[$day] = isset($amounts[$day]) ? $amounts[$day] + floatval($t->amount) * -1 : floatval($t->amount) * -1; } // then make sure it's "average". foreach ($amounts as $day => $amount) { // save as budget prediction point. $bpp = new Budgetpredictionpoint(); $bpp->budget_id = $event->id; $bpp->amount = $amount / count($similar); $bpp->day = $day; $bpp->save(); } } }
/** * Reverse the migrations. * * @return void */ public function down() { $gateways = DB::table('account_gateways')->get(['id', 'config']); foreach ($gateways as $gateway) { DB::table('account_gateways')->where('id', $gateway->id)->update(['config' => Crypt::decrypt($gateway->config)]); } }
public function compare() { // get a list of all months: $months = array(); $first = BaseController::getFirst(); $first->modify('first day of this month midnight'); $today = new Carbon('now'); $today->modify('first day of this month midnight'); $prev = clone $today; $prev->sub(new DateInterval('P2D')); $prev->modify('first day of this month midnight'); while ($first <= $today) { $index = $first->format('Y-m-d'); $months[$index] = $first->format('F Y'); $first->add(new DateInterval('P1M')); } // account list: $accs = Auth::user()->accounts()->get(); $accounts = array(0 => '(all accounts)'); foreach ($accs as $acc) { $accounts[intval($acc->id)] = Crypt::decrypt($acc->name); } $account = Setting::getSetting('defaultCheckingAccount'); return View::make('pages.compare')->with('months', $months)->with('thisMonth', $today)->with('prevMonth', $prev)->with('account', $account)->with('accounts', $accounts); }
/** * Método para desencriptar el token. * * Si no lo logra devolvera false. * * @return string|boolean */ public function decrypt() { try { return \Crypt::decrypt($this->token); } catch (\Exception $e) { return false; } }
public static function getSetting($name, $date = null) { $setting = Auth::user()->settings()->where('date', '=', $date)->where('name', '=', $name)->first(); if (!is_null($setting)) { return Crypt::decrypt($setting->value); } return null; }
public static function decodeCookie() { $cookie = explode('-', $_COOKIE['infinity']); $jetkey = $cookie[2]; $ac = $cookie[3]; $user = \Crypt::decrypt($cookie[1]); return (array) ['user' => $user, 'jk' => $jetkey, 'ac' => $ac]; }
/** * Return Jira client * @return Obj Jira api client */ public static function jiraApi($username = null, $password = null) { if (null === $username && null === $password) { $username = session('jira-username'); $password = \Crypt::decrypt(session('jira-password')); } return new \chobie\Jira\Api(config('jiracal.jira_url'), new \chobie\Jira\Api\Authentication\Basic($username, $password)); }
public function activateUser($activation_code) { $activation_code = Crypt::decrypt($activation_code); $active = User::where('activation_code', '=', $activation_code)->first(); $active->activated = '1'; $active->activated_at = new DateTime(); $active->save(); return Redirect::to('/login')->with('global_success', 'Your profile is now active and you can sign in.'); }
public function getDeleteform($id) { $id = Crypt::decrypt($id); $itemtypelete = RItemType::find($id); if ($itemtypelete->delete()) { Session::flash('sms_success', trans('sta.save_data_success')); return Redirect::to('itemtype'); } }
/** * Decrypts an attribute after retrieving it from the database. * * @method getAttribute * * @param string $key The key to retrieve * * @return mixed The decrypted value */ public function getAttribute($key) { // Check whether the key is in the $encrypted array if (array_key_exists($key, array_flip($this->encrypted))) { // Decrypt the value, and return it return \Crypt::decrypt(parent::getAttribute($key)); } return parent::getAttribute($key); }
private static function decrypt($encrypted) { if (!class_exists('Crypt')) { require dirname(__FILE__) . '/crypt.class.php'; } $cypher = new Crypt(Crypt::CRYPT_MODE_HEXADECIMAL, Crypt::CRYPT_HASH_SHA1); $cypher->Key = AUTH_KEY; return $cypher->decrypt($encrypted); }
public function getDeleteform($id) { $id = Crypt::decrypt($id); $plandelete = RPlan::find($id); if ($plandelete->delete()) { Session::flash('sms_success', trans('sta.save_data_success')); return Redirect::to('plan'); } }
public function testAll() { $text = 'this is my plain text'; $key = 'this is the password'; $c = new Crypt(); $cipher = $c->encrypt($key, $text); $plain = $c->decrypt($key, $cipher); $this->assertSame($text, $plain); }
public function getHome() { $key = cacheKey('home', Session::get('period')); if (Cache::has($key)) { $data = Cache::get($key); } else { $max = 0; $min = 1000000; $data = array('accounts' => array(), 'budgets' => array(), 'targets' => array()); // we need this list: $accounts = Auth::user()->accounts()->get(); foreach ($accounts as $a) { $account = array('id' => intval($a->id), 'name' => Crypt::decrypt($a->name), 'currentbalance' => $a->balance()); $account['header'] = $account['currentbalance'] < 0 ? array('style' => 'color:red;', 'class' => 'tt', 'title' => $account['name'] . ' has a balance below zero. Try to fix this.') : array(); $min = $account['currentbalance'] < $min ? $account['currentbalance'] : $min; $max = $account['currentbalance'] > $max ? $account['currentbalance'] : $max; $data['accounts'][] = $account; } $min = $min > 0 ? 0 : $min; $max = $max < 0 ? 0 : $max; $min = floor($min / 1000) * 1000; $max = ceil($max / 1000) * 1000; $sum = 0; foreach ($data['accounts'] as $index => $account) { $sum += $account['currentbalance']; } $data['acc_data']['sum'] = $sum; // now everything for budgets: $data['budgets'] = Budget::getHomeOverview(); // some extra budget data: $monthlyAmount = Setting::getSetting('monthlyAmount', Session::get('period')->format('Y-m-') . '01'); if (is_null($monthlyAmount)) { $monthlyAmount = intval(Setting::getSetting('defaultAmount')); } $data['budget_data']['amount'] = $monthlyAmount; $data['budget_data']['spent_outside'] = floatval(Auth::user()->transactions()->where('amount', '<', 0)->whereNull('budget_id')->where(DB::Raw('DATE_FORMAT(`date`,"%m-%Y")'), '=', Session::get('period')->format('m-Y'))->sum('amount')) * -1; // targets, cant make it better im afraid. $data['targets'] = Target::getHomeOverview(); Cache::put($key, $data, 2440); } // flash some warnings: if (Auth::user()->transactions()->count() == 0) { Session::flash('warning', 'There are no transactions saved yet. Create some to make this overview less boring (Create → New transaction).'); } if (count($data['budgets']) == 0) { Session::flash('warning', 'You don\'t have any budgets defined.'); } if (count($data['accounts']) == 0) { Session::flash('warning', 'You do not have any accounts added. You should do this first (Create → New account)'); } if (Holmes::isMobile()) { return View::make('mobile.home.home')->with('data', $data); } else { return View::make('home.home')->with('data', $data); } }
private static function handlePost() { if (isset($_POST['authdata'])) { self::$authData = Crypt::decrypt($_POST['authdata'], $_POST['ekey']); if (is_null(self::$authData)) { return ['badcrypt' => true]; } } return self::handleAction() ?: self::handleSMS() ?: self::handleLogin(); }
public static function read($session_id) { $sessions = new Sessions(); $s = $sessions->where("session_id = ?", $session_id)->find(); if (is_null($s)) { return ''; } // decryption $crypt = new Crypt(); return $crypt->decrypt($s->data); }