Changeset 8a258ab for app/Http


Ignore:
Timestamp:
08/26/24 13:20:24 (4 months ago)
Author:
bube-ristovska <ristovska725@…>
Branches:
main
Children:
5372778
Parents:
092fcda
Message:

hashed passwords

File:
1 edited

Legend:

Unmodified
Added
Removed
  • app/Http/Controllers/SessionsController.php

    r092fcda r8a258ab  
    88use Illuminate\Support\Facades\DB;
    99use Illuminate\Support\Facades\Session;
     10use Illuminate\Support\Facades\Hash;
    1011
    1112class SessionsController extends Controller
    1213{
     14    function verifyPassword($inputPassword, $storedHash, $salt)
     15    {
     16        $hashedInputPassword = crypt($inputPassword . $salt, $storedHash);
     17
     18        return $hashedInputPassword === $storedHash;
     19    }
    1320    public function store()
    1421    {
     
    2936        if($is_officer!=null) {
    3037            $pass = DB::select('select o_password from officer where o_badge_no = :o_badge_no;', ['o_badge_no' => $badge_no]);
     38            $salt = DB::select('select salt from officer where o_badge_no = :o_badge_no;', ['o_badge_no' => $badge_no]);
    3139            $policeman = false;
    3240        } else {
    3341            $pass = DB::select('select p_password from policeman where badge_no = :badge_no;', ['badge_no' => $badge_no]);
     42            $salt = DB::select('select salt from policeman where badge_no = :badge_no;', ['badge_no' => $badge_no]);
     43
    3444        }
    3545
     
    3848            break; // Break after the first key-value pair
    3949        }
    40 
    41         if ($value == $password) {
     50        foreach ($salt[0] as $key => $val) {
     51            $value2 = $val;
     52            break; // Break after the first key-value pair
     53        }
     54        if ($this->verifyPassword($password, $value, $value2)) {
    4255            // Authentication passed
    4356            Session::put('badge_no', $badge_no);
Note: See TracChangeset for help on using the changeset viewer.