Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [skrypt] uniwersalny skrypcik logowania
epud
post
Post #1





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 5.06.2006

Ostrzeżenie: (0%)
-----


jako, że zaczynam dopiero zabawe z obiektowym php prosze o ocene skrypciku na ponize, jest to "uniwersalny" skrypcik logowania uzytkownika do systemu... zalozenie bylo takie abym mogl to prosto przystosowac do innych projetkow bez za duzego grzebania w kodzie, dla tego podajemy nazwe tabeli z uzytkownikami, i nazwe pol z loginem i haslem

co myslicie nadaje sie?

a pod wzgledem obiektowym?

  1. <?php 
  2. class auth{
  3. var $db = NULL;
  4. var $table_name;
  5. var $login_name;
  6. var $pass_name;
  7. var $md5;
  8. var $login;
  9. var $pass;
  10. var $dbpass;
  11. var $errors = array();
  12. public function __construct($db, $table_name, $login_name, $pass_name, $md5 = false){
  13. //$_SESSION['isLoggedIn'] = false;
  14. $this -> db = $db;
  15. $this -> table_name = $table_name;
  16. $this -> login_name = $login_name;
  17. $this -> pass_name = $pass_name;
  18. $this -> md5 = $md5;
  19. }
  20. public function authorize($login, $pass){
  21. if(empty($login) || empty($pass)){
  22. array_push($this -> errors, 'login i hasło nie mogą być puste');
  23. return false;
  24. }
  25. $this -> login = $login;
  26. if($this -> md5){
  27. $this -> pass = md5($pass);
  28. }
  29. else{
  30. $this -> pass = $pass;
  31. }
  32. if($this -> getPass()){
  33. if($this -> pass == $this -> dbpass){
  34. $_SESSION['isLoggedIn'] = true;
  35. $_SESSION['userData'] = $this -> getUserData();
  36. header("Location: index.php");
  37. }
  38. else{
  39. array_push($this -> errors, 'błędny login lub hasło');
  40. }
  41. }
  42. else{
  43. array_push($this -> errors, 'błędny login lub hasło');
  44. }
  45. }
  46. private function getPass(){
  47. $this -> dbpass = $this -> db -> GetOne("SELECT ". $this -> pass_name ." FROM ". $this -> table_name ." WHERE ". $this -> login_name." = '".$this -> login."'");
  48. if($this -> dbpass){
  49. return true;
  50. }
  51. return false;
  52. }
  53. public function isLoggedIn(){
  54. return $_SESSION['isLoggedIn'];
  55. }
  56. private function getUserData(){
  57. return trim_array($this -> db -> GetRow("SELECT * FROM ".$this -> table_name." WHERE ".$this -> login_name." = '".$this -> login."'"));
  58. }
  59. }
  60. ?>


sprawdzanie czy zalogowany czy nie..

  1. <?php 
  2. $auth = new auth($db, PREFIX."users", 'user_name', 'user_pass', true);
  3. /* END AUTH */
  4.  
  5. if($auth -> isLoggedIn()){//jesli zalogowany
  6. $smarty -> display('index.tpl');
  7. }
  8. else{//jesli nie zalogowany
  9. $smarty -> display('loginForm.tpl');
  10. }//if($auth -> isLoggedIn())
  11. ?>

wersyfikacjia usera
  1. <?php
  2. $auth = new auth($db, PREFIX."users", 'user_name', 'user_pass', true);
  3. $auth -> authorize($_POST['login']['user_name'], $_POST['login']['user_pass']);
  4. ?>



z gory dzieki za wszelkie wypowiedzi winksmiley.jpg

Ten post edytował epud 5.06.2006, 18:03:37
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 06:33