/** * 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); }
public function index() { $encryptedkey = Crypt::encrypt("joomla"); Config::set('session.driver', 'native'); Session::put('api_key', $encryptedkey); return Response::json(array('status' => 'OK', '_token' => $encryptedkey)); }
public function postLogin(Request $request) { $this->validate($request, ['user_id' => 'required', 'password' => 'required']); $credentials = $request->only('user_id', 'password'); $redirect = $this->redirectPath(); $lock_new_users = true; $try = false; if (User::find($credentials['user_id'])) { // The user exists $try = true; } else { if ($lock_new_users) { return redirect('/locked'); } else { if (($person = Person::find($credentials['user_id'])) && DataSource::check_login($credentials['user_id'], $credentials['password'])) { // The ID exists and details are correct, but there isn't an account for it. Make one. $user = User::create(['user_id' => $credentials['user_id'], 'name' => $person->name, 'password' => \Crypt::encrypt($credentials['password']), 'is_queued' => true]); \Queue::push(new PrepareUser($user)); $redirect = '/setup'; $try = true; } } } if ($try && Auth::attempt($credentials, $request->has('remember'))) { return redirect()->intended($redirect); } return redirect($this->loginPath())->withInput($request->only('user_id', 'remember'))->withErrors(['user_id' => $this->getFailedLoginMessage()]); }
/** * Encrypt value * * @param string $key * @param mixed $value * @return $this */ public function setAttribute($key, $value) { if (in_array($key, $this->encryptable)) { return parent::setAttribute($key, \Crypt::encrypt($value)); } return parent::setAttribute($key, $value); }
/** * Run the migrations. * * @return void */ public function up() { $gateways = DB::table('account_gateways')->get(['id', 'config']); foreach ($gateways as $gateway) { DB::table('account_gateways')->where('id', $gateway->id)->update(['config' => Crypt::encrypt($gateway->config)]); } }
/** * Show the form for creating a new resource. * POST /account/create * * @return Response */ public function create() { //perform Register Action $rules = ['email' => 'required|email|unique:users', 'password' => 'required|min:6']; $v = Validator::make(Input::all(), $rules); if ($v->fails()) { return Redirect::route('register')->withErrors($v)->withInput(); } else { $users = new User(); $users->first_name = Input::get('fname'); $users->last_name = Input::get('lname'); $users->username = Input::get('username'); $users->email = Input::get('email'); $users->password = Hash::make(Input::get('password')); $send = $users->save(); if ($send) { Mail::send('emails.activation', array('key' => Crypt::encrypt(Input::get('email'))), function ($message) { $message->to(Input::get('email'), Input::get('fname') . ' ' . Input::get('lname'))->subject('Welcome! Please Activate Your Account'); }); $newUser = User::find($users->id); Auth::login($newUser); return Redirect::to('home'); } } }
public function postCreate() { $rules = array('txtRol' => 'required|numeric|min:1', 'txtEmail' => 'required|email|min:8|max:100', 'txtPassword' => 'required|min:6|max:100', "txtNombres" => "required|min:2|max:100", "txtApellidos" => "required|min:2|max:100", "username" => "required|min:3|max:20|unique:users", "txtEstado" => "required|numeric|min:0|max:1"); $messages = array('required' => 'El campo :attribute es obligatorio.', 'min' => 'El campo :attribute no puede tener menos de :min carácteres.', 'email' => 'El campo :attribute debe ser un email válido.', 'max' => 'El campo :attribute no puede tener más de :min carácteres.', 'unique' => 'El :attribute ingresado ya existe en la base de datos', "numeric" => "El campo :attribute debe ser un numero"); $friendly_names = array('username' => 'Nombre de Usuario', 'txtPassword' => 'Contraseña', "txtNombres" => "Nombres", "txtApellidos" => "Apellidos", "txtEstado" => "Estado", "txtEmail" => "Email", "txtRol" => "Rol"); $validation = Validator::make(Input::all(), $rules, $messages); $validation->setAttributeNames($friendly_names); if ($validation->fails()) { return Redirect::to('usuarios/ausuario')->withErrors($validation)->withInput(); } else { DB::transaction(function () { $usuario = new Usuario(); $usuario->roles_id = Input::get("txtRol"); $usuario->nombres = Input::get("txtNombres"); $usuario->apellidos = Input::get("txtApellidos"); $usuario->email = Input::get("txtEmail"); $usuario->password = Hash::make(Input::get("txtPassword")); $usuario->contrasenia = Crypt::encrypt(Input::get("txtPassword")); $usuario->username = Input::get("username"); $usuario->fechaCreacion = new DateTime(); $usuario->estado = Input::get("txtEstado"); $usuario->save(); }); return Redirect::to("admin")->with("insertar", true); } }
public function saveUserInfo() { if (!isset($_SESSION)) { session_start(); } $code = \Input::get('code'); $lti = \Input::get('lti'); $instanceFromDB = LtiConfigurations::find($lti); $clientId = $instanceFromDB['DeveloperId']; $developerSecret = $instanceFromDB['DeveloperSecret']; $opts = array('http' => array('method' => 'POST')); $context = stream_context_create($opts); $url = "https://{$_SESSION['domain']}/login/oauth2/token?client_id={$clientId}&client_secret={$developerSecret}&code={$code}"; $userTokenJSON = file_get_contents($url, false, $context, -1, 40000); $userToken = json_decode($userTokenJSON); $actualToken = $userToken->access_token; $encryptedToken = \Crypt::encrypt($actualToken); $_SESSION['userToken'] = $encryptedToken; //store encrypted token in the database $courseId = $_SESSION['courseID']; $userId = $_SESSION['userID']; $user = new User(); $user->user_id = $userId; $user->course_id = $courseId; $user->encrypted_token = $encryptedToken; $user->save(); echo "App has been approved. Please reload this page"; }
public function create() { $data = Input::all(); $promo = new Promo(); $promo->days = Input::get('days'); $promo->code = Crypt::encrypt(Input::get('code')); $promo->status = 0; $promo->colony_id = Input::get('colony_id'); if ($promo->save()) { $user_id = Input::get('admin_colonia'); $admin_user = DB::connection('habitaria_dev')->select('select email from users where id = ? ', [$user_id]); foreach ($admin_user as $user) { $admin_email = $user->email; } $admin_neighbor = Neighbors::where('user_id', '=', $user_id)->first(); $colony_data = Colony::where('id', '=', $promo->colony_id)->first(); $colony_name = $colony_data->name; $data = array('email' => $admin_email, 'days' => $promo->days, 'code' => Crypt::decrypt($promo->code), 'colony' => $colony_name, 'admin' => $admin_neighbor->name . ' ' . $admin_neighbor->last_name); Mail::send('emails.cupon_promo', $data, function ($message) use($admin_email) { $message->subject('Promo de HABITARIA'); $message->to($admin_email); }); $notice_msg = 'Promo enviada al administrador de la Colonia: ' . $colony_name; return Redirect::action('PromoController@report_promo', $promo->colony_id)->with('error', false)->with('msg', $notice_msg)->with('class', 'info'); } }
public function saveUserInfo() { if (!isset($_SESSION)) { session_start(); } $code = \Input::get('code'); $lti = \Input::get('lti'); $instanceFromDB = LtiConfigurations::find($lti); $clientId = $instanceFromDB['DeveloperId']; $developerSecret = $instanceFromDB['DeveloperSecret']; $opts = array('http' => array('method' => 'POST')); $context = stream_context_create($opts); $url = "https://{$_SESSION['domain']}/login/oauth2/token?client_id={$clientId}&client_secret={$developerSecret}&code={$code}"; $userTokenJSON = file_get_contents($url, false, $context, -1, 40000); $userToken = json_decode($userTokenJSON); $actualToken = $userToken->access_token; $encryptedToken = \Crypt::encrypt($actualToken); $_SESSION['userToken'] = $encryptedToken; //store encrypted token in the database $courseId = $_SESSION['courseID']; $userId = $_SESSION['userID']; //make sure we have the user stored in the user table and in the userCourse table. $roots = new Roots(); //when we get the user from the LMS it gets stored in the DB. $roots->getUser($userId); $dbHelper = new DbHelper(); $role = $dbHelper->getRole('Approver'); $userCourse = UserCourse::firstOrNew(array('user_id' => $userId, 'course_id' => $courseId)); $userCourse->user_id = $userId; $userCourse->course_id = $courseId; $userCourse->role = $role->id; $userCourse->encrypted_token = $encryptedToken; $userCourse->save(); echo "App has been approved. Please reload this page"; }
private function _updatePerfil($status_image) { if ($status_image == 'no_image') { // No subió ninguna imágen $id = Auth::id(); $user = User::find($id); $user->name = Input::get('name'); $user->last_name = Input::get('lastname'); $user->email = Input::get('email'); $user->password = Crypt::encrypt(Input::get('password')); $user->save(); return true; } else { // Subió una imágen nueva. $save_name_file = date('Y.m.d.H_m_s') . Input::file('file')->getClientOriginalName(); $file_move = Input::file('file')->move(public_path() . '/uploads/perfil/', $save_name_file); if ($file_move) { $id = Auth::id(); $user = User::find($id); $user->name = Input::get('name'); $user->last_name = Input::get('lastname'); $user->email = Input::get('email'); $user->password = Crypt::encrypt(Input::get('password')); $user->image = $save_name_file; $user->save(); return true; } else { return false; } } }
public function postNew() { if (Input::has('save')) { if (Input::get('employee') == 0 || Input::get('organization') == 0 || Input::get('r_plan') == 0 || Input::get('specialist') == 0 || strlen(Input::get('title')) < 2 || strlen(Input::get('description')) < 2) { Session::flash('sms_warn', trans('sta.require_field')); } else { $request = new RRequest(); $request->request_by_id = Input::get('employee'); $request->for_organization_id = Input::get('organization'); $request->for_planning_id = Input::get('r_plan'); $request->to_department_id = Input::get('specialist'); $request->request_title = Input::get('title'); $request->description = Input::get('description'); $request->request_date = date('Y-m-d'); $request->created_by = Auth::user()->employee_id; if ($request->save()) { Session::flash('sms_success', trans('sta.save_data_success')); return Redirect::to('branch_request/general/' . Crypt::encrypt($request->id)); } } } $organizations = $this->array_list(Organization::list_item()); $employees = $this->array_list(Employee::list_item()); $department = $this->array_list(Department::list_item()); $r_plans = $this->array_list(Rplan::list_item()); return View::make('branch_request.new', array('organizations' => $organizations, 'employees' => $employees, 'specialist' => $department, 'r_plans' => $r_plans)); }
private function check($d) { global $LANGUAGES; if (!Data::checkFilled($d['language'])) { Error::msg("Por favor, escolha uma linguagem.", __METHOD__); } if (!in_array($d['language'], array_keys($LANGUAGES))) { Error::msg("A linguagem '" . $d['language'] . "' não é válida", __METHOD__); } if (empty($d['source'])) { Error::msg("Por favor, preencha o campo <b>código fonte</b>.", __METHOD__); } require_once b1n_PATH_LIB . "/Crypt.lib.php"; $seccode = $d['seccode']; $seccode = Crypt::encrypt(strtolower($seccode)); if (!isset($_SESSION['seccode'])) { Error::msg("Digite o que está escrito na imagem corretamente.", __METHOD__); } if (strcmp($seccode, $_SESSION['seccode']) != 0) { Error::msg("Digite o que está escrito na imagem corretamente.", __METHOD__); } $md5 = md5($d['source']); $query = "SELECT pas_id FROM paste WHERE pas_md5 = '" . $md5 . "'"; $rs = $this->sql->singleQuery($query); if (is_array($rs) && count($rs)) { $id = base_convert($rs['pas_id'], 10, b1n_CODE_BASE); $url = b1n_URL_ID . $id; Error::msg("Já existe um código igual a esse no banco de dados.<br />\n Veja: <a href='{$url}'>{$url}</a>", __METHOD__); } return true; }
public function Create() { $rules = array('username' => 'required', 'level' => 'required', 'names' => 'required', 'last_name' => 'required', 'ci_num' => 'required', 'correo' => 'required|email', 'telephone' => 'required|numeric', 'adress' => 'required', 'password' => 'required'); $validacion = Validator::make(Input::all(), $rules); if ($validacion->fails()) { return Redirect::back()->withErrors($validacion); } else { $password = Input::get('password'); $persona = new Persona(); $user = new User(); $persona->nombres = Input::get('names'); $persona->apellidos = Input::get('last_name'); $persona->ci = Input::get('ci_num'); $persona->telefono = Input::get('telephone'); $persona->direccion = Input::get('adress'); $persona->save(); $persona = Persona::where('ci', '=', Input::get('ci_num'))->first(); $user->username = Input::get('username'); $user->password = Hash::make($password); $user->encry = Crypt::encrypt($password); $user->nivel = Input::get('level'); $user->email = Input::get('correo'); $user->persona_id = $persona->id; $user->save(); return Redirect::to('admi')->with('status', 'ok_create'); } }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Requests\SignUpRequest $request) { // $usermodel = new User(); $all = $request->all(); try { $password = $all["password"]; $payload = \Crypt::encrypt($password); $all["password"] = $payload; $all['role'] = 5; if (isset($all['_token'])) { unset($all['_token']); } $user = $usermodel->newUser($all); if ($user) { $login = $this->login($all); return $login; } dd("signup failed!"); } catch (Exception $e) { $message = $e->getMessage(); $code = $e->getCode(); dd(["message" => $message, "code" => $code]); } }
public function postSave() { if (\Auth::user()->role != "admin") { abort(401); } $data = \Input::all(); $validator = \Validator::make($data, ['name' => 'required']); if ($validator->fails()) { // The given data did not pass validation abort(400); } if (isset($data["tsigname"]) && $data["tsigname"] != "") { $data["tsigname"] = \Crypt::encrypt($data["tsigname"]); } if (isset($data["tsigkey"]) && $data["tsigkey"] != "") { $data["tsigkey"] = \Crypt::encrypt($data["tsigkey"]); } if (\Input::has('id')) { $zone = \App\Zone::find(\Input::get("id")); $zone->update($data); } else { $zone = \App\Zone::create($data); } return $this->getAllZones(); }
public function dologin() { $params = Input::all(); if (empty($params['username'])) { Session::flash('error', '用户名必须填写'); return Redirect::route('login'); } if (empty($params['password'])) { Session::flash('error', '密码必须填写'); return Redirect::route('login'); } if (empty($params['captcha'])) { Session::flash('error', '验证码必须填写'); return Redirect::route('login'); } if (!$this->_validate_captcha($params['captcha'])) { Session::flash('error', '验证码错误'); return Redirect::route('login'); } $password = md5(md5($params['password'])); $admin = AdminORM::whereUsername($params['username'])->wherePwd($password)->where('status', '<>', BaseORM::DISABLE)->first(); if (!empty($admin)) { Session::flash('success', '登陆成功'); $admin_id_cookie = Cookie::forever('admin_id', $admin->id); $admin_username_cookie = Cookie::forever('admin_username', $admin->username); $k_cookie = Cookie::forever('k', Crypt::encrypt($admin->id . $admin->username)); $login_time_cookie = Cookie::forever('login_time', time()); $admin->last_login_time = date('Y-m-d H:i:s'); $admin->save(); return Redirect::route('home')->withCookie($k_cookie)->withCookie($admin_id_cookie)->withCookie($admin_username_cookie)->withCookie($login_time_cookie); } else { Session::flash('error', '用户没找到'); return Redirect::route('login'); } }
public function save() { // Get all inputs $input = Input::all(); // Retrive the project details $project = Project::find($input['project_id']); // Assign values $project->name = $input['name']; $project->project_type = $input['project_type']; $project->description = $input['description']; $project->client_name = $input['client_name']; $project->start_at = $input['start_at']; $project->complete_at = $input['complete_at']; // Identify if this project is on hold or not if (isset($input['status'])) { $project->status = 2; } else { $project->status = 1; } // Update the project details $project->save(); // Assign each user in a project foreach (array_merge($input['developers'], $input['qc']) as $key => $value) { $user = ProjectUsers::firstOrCreate(array('project_id' => $input['project_id'], 'user_id' => $value)); $user->key = Crypt::encrypt(time()); $user->save(); } // Redirect to project page with message return Redirect::to('/project/' . $project->slug)->with('flash_msg', 'This project was successfully updated!'); }
/** * Called by web server<br> * 生成并返回凭证。生成的凭证默认存储在Session里。<br> * 你可以改写该函数,存储在数据库、文件里、Memcache里都行。凭证数据结构也可以改。 * @return array */ public function outputCredential() { $token = str_random(40); $sessionId = \Session::getId(); $credential = array(\Crypt::encrypt($sessionId), \Crypt::encrypt($token)); \Session::put($this->tokenKey, $token); return $credential; }
function _returnCryptAjax($result) { @header("Content-type: text/html; charset=" . YApp::getConfig('YUC_RESPONSE_CHARSET')); @header("Pragma:no-cache\r\n"); @header("Cache-Control:no-cache\r\n"); @header("Expires:0\r\n"); echo Crypt::encrypt(json_encode($result), YApp::getConfig("YUC_SECURE_KEY")); }
public static function gURL($src, $ext, $width, $height, $flags = 0, $dir = 'dir', $mode = 'full_path') { $crypt = new Crypt(); $crypt->Mode = Crypt::MODE_HEX; $crypt->Key = self::_CRYPT; switch ($mode) { default: return NEnvironment::getConfig()->gallery[$dir] . '/temp/' . $src . '|' . $crypt->encrypt($width . '|' . $height . '|' . $flags) . '.' . $ext; break; case 'image_name': return $src . '|' . $crypt->encrypt($width . '|' . $height . '|' . $flags) . '.' . $ext; break; case 'dir': return NEnvironment::getConfig()->gallery[$dir] . '/temp/'; break; } }
public function run() { $faker = Faker::create('en_GB'); $dcs = [['@hasla.org.uk', 'DC=hasla,DC=org,DC=uk', '8454612-DC01.hasla.org.uk', 'web.team', Crypt::encrypt('Hastings1'), 0, 389]]; foreach (range(1, count($dcs)) as $index) { DomainController::create(['account_suffix' => $dcs[$index - 1][0], 'base_dn' => $dcs[$index - 1][1], 'domain_controller' => $dcs[$index - 1][2], 'admin_username' => $dcs[$index - 1][3], 'admin_password' => $dcs[$index - 1][4], 'use_ssl' => $dcs[$index - 1][5], 'ad_port' => $dcs[$index - 1][6]]); } }
public function loginUser() { if (\Auth::attempt(array('email' => \Input::get('email'), 'password' => \Input::get('password')))) { $user = \User::where('email', \Input::get('email'))->first(); $encrypted = \Crypt::encrypt($user); return \Response::json(['loginStatus' => true, 'token' => $encrypted]); } return \Response::json(['loginStatus' => false]); }
/** * @return string * @throws \PeskyORM\Exception\DbObjectException */ public function getPasswordRecoveryAccessKey() { /** @var CmfDbObject|ResetsPasswordsViaAccessKey $this */ $data = ['account_id' => $this->_getPkValue(), 'expires_at' => time() + config('auth.passwords.' . \Auth::getDefaultDriver() . 'expire', 60) * 60]; foreach ($this->getAdditionalFieldsForPasswordRecoveryAccessKey() as $fieldName) { $data[$fieldName] = $this->_getFieldValue($fieldName); } return \Crypt::encrypt(json_encode($data)); }
private static function encrypt($plain_text) { 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->encrypt($plain_text); }
/** * This function displays the notifications options to be selected by user * @return string */ public function render() { global $xoopsUser, $cuSettings; if (!$xoopsUser) { return null; } $items = array(); $user_groups = $xoopsUser->getGroups(); $crypt = new Crypt(null, $cuSettings->secretkey); $subscriptions = $this->subscriptions(); // Check permissions foreach ($this->items as $item) { $item->type = $item->type != '' ? $item->type : 'module'; $item->hash = $crypt->encrypt(json_encode(array('event' => $item->event, 'element' => $item->element, 'type' => $item->type, 'params' => $item->params))); // Check if users is subscribed to current event $id = hash('crc32', $item->event . ':' . $item->element . ':' . $item->type . ':' . $item->params); if (array_key_exists($id, $subscriptions)) { $item->subscribed = true; } else { $item->subscribed = false; } if (!is_array($item->permissions) || count($item->permissions) <= 0) { $items[] = $item->data(); continue; } // Check if users were provided and current user is allowed if (array_key_exists('users', $item->permissions) && count($item->permissions['users']) > 0) { if (in_array($xoopsUser->uid(), $item->permissions['users'])) { $items[] = $item->data(); continue; } } if (count($item->permissions['groups']) <= 0) { $items[] = $item->data(); continue; } // Check if groups were provided and current user group is allowed if (array_key_exists('groups', $item->permissions) && count($item->permissions['groups']) > 0) { $intersect = array_intersect($item->permissions['groups'], $user_groups); if (!empty($intersect)) { $items[] = $item->data(); continue; } } } $this->items = array(); if (empty($items)) { return null; } RMTemplate::get()->add_script('cu-handler.js', 'rmcommon', array('footer' => 1)); ob_start(); include RMTemplate::get()->get_template('rmc-notifications-options.php', 'module', 'rmcommon'); $template = ob_get_clean(); // Clear notifications items $this::$index++; return $template; }
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); }
/** * Create basic data for secret creation. * * @return data */ public function secretData() { $data['secret_intermediate'] = $this->faker->word(32); $data['secret'] = Crypt::encrypt($data['secret_intermediate']); $data['uuid4_intermediate'] = Uuid::uuid4()->toString(); $data['uuid4'] = crypt($data['uuid4_intermediate'], '$6$rounds=5000$' . getenv('APP_SALT') . '$'); $data['count_views'] = $this->faker->numberBetween(5, 1000); return $data; }
/** * Encrypts an attribute before storing it in the database. * * @method setAttribute * * @param string $key The key being set * @param mixed $value The value to set */ public function setAttribute($key, $value) { // Check whether the key is in the $encrypted array if (array_key_exists($key, array_flip($this->encrypted))) { // Encrypt the value, and store it parent::setAttribute($key, \Crypt::encrypt($value)); return; } return parent::setAttribute($key, $value); }
/** * @desc Genearate a token * @return Boolean */ public static function generate() { // Get the current tokens $tokens = Session::get('tokens'); // Create a new one $tokens[] = Crypt::encrypt(str_shuffle(Config::get('csrf.salt')), '6g67ba321', 'md5'); // Set it in the session Session::set('tokens', $tokens); return !!Session::get('tokens'); }