public function postIndex() { #set post ke params variable, agar bisa dikirim ke tampilan login $this->params = $_POST; if (!in_array($_POST['type'], $this->user_types)) { #error tipe login salah $this->params['error_message'] = 'Tipe login salah'; #buka lagi halaman login $this->getIndex(); } else { // $this->pdo->enable_debug(); $row = $this->pdo->select("SELECT * FROM {$_POST['type']} WHERE username = ? AND password = ?", [$_POST['username'], hashpassword($_POST['password'])], false); #error ID atau password salah if (!$row || count($row) == 0) { $this->params['error_message'] = 'ID atau password Anda salah'; $this->getIndex(); } else { #berhasil login #set session login switch ($_POST['type']) { case 'siswa': $this->user_logged->set_user_logged(['level' => 'siswa', 'hak' => 'siswa', 'admin' => $_POST['username'], 'user' => $row['id_siswa'], 'id' => $row['id_siswa'], 'agent' => $_SERVER['HTTP_USER_AGENT'], 'username' => $_POST['username'], 'status' => $row['status']]); break; case 'guru': $this->user_logged->set_user_logged(['level' => 'guru', 'hak' => 'guru', 'admin' => $_POST['username'], 'user' => $row['id_guru'], 'id' => $row['id_guru'], 'agent' => $_SERVER['HTTP_USER_AGENT'], 'username' => $_POST['username'], 'status' => 'active']); break; case 'admin': $this->user_logged->set_user_logged(['level' => 'admin', 'hak' => 'admin', 'admin' => $_POST['username'], 'user' => $row['id_admin'], 'id' => $row['id_admin'], 'agent' => $_SERVER['HTTP_USER_AGENT'], 'username' => $_POST['username'], 'status' => 'active']); break; } #redirect ke halaman index redirect_to("{$_POST['type']}/profile"); } } }
public function run() { $email = $_POST['login']; $password = hashpassword('md5', $_POST['password'], HASH_PASSWORD_KEY); $admin = Admin::login($email, $password); if ($admin) { // login Session::init(); Session::set('role', $admin->admin_role); Session::set('loggedIn', true); Session::set('admin_id', $admin->admin_id); header('location: ../index'); } else { $_SESSION['adminmessage'] = "Username or Password is wrong."; header('location: ../login'); } }
public function update($id) { if (isset($_POST['name']) && !empty($_POST['name']) && isset($_POST['email']) && !empty($_POST['email']) && isset($_POST['role']) && !empty($_POST['role'])) { $admin = Admin::find_by_id($id); $admin->admin_name = $_POST['name']; $admin->admin_email = $_POST['email']; if (isset($_POST['password']) && !empty($_POST['password']) && $_POST['rpassword'] == $_POST['password']) { $admin->admin_password = hashpassword('md5', $_POST['password'], HASH_PASSWORD_KEY); } $admin->admin_role = $_POST['role']; if ($admin->update()) { $_SESSION['adminmessage'] = "Admin updated successfully and Saved"; header("location: ../admins"); } else { $_SESSION['adminmessage'] = "Admin Not Updated"; header("location: ../admins"); } } else { $_SESSION['adminmessage'] = "Admin could not Update at this time, Please try again."; header("location: ../admins"); } }
public function reg() { if (isset($_POST['nickname'])) { $post = $_POST; dump($post); if ($post['password'] != $post['repassword']) { echo "两次密码不一至"; exit; } if (DB::fetch_first("select * from %t where email=%s", array('member', $post['email']))) { exit('邮箱被占用'); } $post['salt'] = getRandStr(); $post['createtime'] = TIME; $id = DB::insert('member', $post); if ($id) { $up['password'] = hashpassword($id, $post['password'], $post['salt']); DB::update('member', $up, 'id=' . $id); $this->redirect('Login/index'); } exit; } include template(); }
/** * 验证码密 * @param $uid * @param $password * @param $salt * @param $_pass * @return bool */ function checkpassword($uid, $password, $salt, $_pass) { return hashpassword($uid, $_pass, $salt) == $password ? true : false; }
public function postIndex() { $this->params = $_POST; $validate = new Validate(); #validate no_ijazah $no_ijazah_exist = $this->pdo->select('SELECT COUNT(1) AS `count` FROM `siswa` WHERE `no_ijazah` = ?', [$this->params['no_ijazah']], false); $validate->isTrue('No Ijazah', $no_ijazah_exist['count'] == 0, 'No ijazah sudah terdaftar'); #validate nama $validate->is_length('Nama Lengkap', $this->params['nama'], 3); #validate Nama Ayah $validate->is_length('Nama Ayah', $this->params['nama_ayah'], 3); #validate Nama Ibu $validate->is_length('Nama Ibu', $this->params['nama_ibu'], 3); #validate Nama Wali $validate->is_length('Nama Wali', $this->params['nama_wali'], 3); #validate Alamat Lengkap Orang Tua $validate->is_length('Alamat Lengkap Orangtua', $this->params['alamat_orangtua'], 3); #validate Pekerjaan Ayah $validate->is_length('Pekerjaan Ayah', $this->params['pekerjaan_ayah'], 5); #validate tanggal lahir $validate->is_valid_tanggal_lahir('Tanggal Lahir', $this->params['tanggal_lahir']); $validate->is_valid_tanggal_lahir('Tanggal Lahir', $this->params['tanggal_lahir']); #validate jenis kelamin $validate->isTrue('Jenis Kelamin', !empty($this->params['jenis_kelamin']) && in_array($this->params['jenis_kelamin'], ['pria', 'wanita']), 'Pilihan jenis kelamin antara pria atau wanita'); #validate email $validate->is_valid_email('Email', $this->params['email']); $email_exist = $this->pdo->select('SELECT COUNT(1) AS `count` FROM `siswa` WHERE `email` = ?', [$this->params['email']], false); $validate->isTrue('Email', $email_exist['count'] == 0, 'Email sudah terdaftar'); #validate tanggal lahir $validate->is_valid_tanggal_lahir('Tanggal Lahir', $this->params['tanggal_lahir']); #validate no handphone $validate->is_valid_nohandphone('No Handphone', $this->params['no_handphone']); #Alamat $validate->is_length('Alamat', $this->params['alamat'], 10); #Agama $validate->is_valid_agama('Agama', $this->params['agama']); #Asal Sekolah $validate->is_length('Asal Sekolah', $this->params['asal_sekolah'], 10); #Tahun Lulus $validate->is_length('Tahun Lulus', $this->params['tahun_lulus_ijazah'], 4); #Username $validate->is_length('Username', $this->params['username'], 5); $username_exist = $this->pdo->select('SELECT COUNT(1) AS `count` FROM `siswa` WHERE `username` = ?', [$this->params['username']], false); $validate->isTrue('Username', $username_exist['count'] == 0, 'Username sudah terdaftar, silahkan coba gunakan username yang lain'); #Password $validate->is_length('Password', $this->params['password'], 5); #Confirm Password $validate->is_equal('Confirm Password', $this->params['confirm_password'], 'Password', $this->params['password']); #cek jika ada error validasi $this->params['error_message'] = $validate->show_errors(); #validasi error if (!empty($this->params['error_message'])) { $this->getIndex(); } else { // var_dump($this->params); die; #validasi sukses $this->pdo->insert('INSERT INTO `siswa` (`username`, `password`, `status`, `nama`, `alamat`, `no_ijazah`, `tanggal_lahir`, `jenis_kelamin`, `email`, `no_handphone`, `agama`, `tahun_lulus_ijazah`, `nama_ayah`, `nama_ibu`, `nama_wali`, `alamat_orangtua`, `pekerjaan_ayah`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [$this->params['username'], hashpassword($this->params['password']), 'baru', $this->params['nama'], $this->params['alamat'], $this->params['no_ijazah'], date('Y-m-d', strtotime($this->params['tanggal_lahir'])), $this->params['jenis_kelamin'], $this->params['email'], $this->params['no_handphone'], $this->params['agama'], $this->params['tahun_lulus_ijazah'], $this->params['nama_ayah'], $this->params['nama_ibu'], $this->params['nama_wali'], $this->params['alamat_orangtua'], $this->params['pekerjaan_ayah']]); #set sukses msg to session flashdata $this->user_logged->set_flashdata('register_sukses', $validate->show_success_message('Anda sudah berhasil register, silahkan login')); #redirect ke halaman login redirect_to("login"); } }
function post_register($data) { if (empty($data->username) and empty($data->password)) { throw new Exception("Login ou senha precisam ser preenchidos"); } #require_once 'helpers/helperPassword.php'; $response["password"] = hashpassword($data->password); $response["username"] = $data->username; $response["message"] = "Usuario registrado"; return json_encode($response); }