viewing paste Unknown #57332 | PHP

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
/**
 * TASK
 * 
 * This is production code you found in the codebase. It was clearly written by very junior developer.
 * It turns out you have some time to work on that and improve it to meet the best quality and industry standards.
 * 
 */
 
class AuthenticationManager {
    // private $users = [];
  
    public $sql;
 
    public function __construct() {
        $this->sql = new Sql('http://localhost:3306', 'mysql_user', '4sfynvasdere');
    }
 
    public function authenticate($username, $password) {
        $user = $this->sql->query("SELECT * FROM users WHERE login = $username AND password = $password");
        
        if ($user) {
            return true;
        }
        return false;
    }
 
    public function logAccess($username) {
        // Log access
        file_put_contents('access.log', "$username accessed the system.\n", FILE_APPEND);
    }
 
    public function isAdmin($username) {
        return $username === 'admin';
    }
  
    public function registerUser($name, $lastName, $email, $password)
    {
        $this->sql->insert('INSERT INTO users VALUES('. $name .', '. $lastName .', '. $email .', '. $password .')');
        $smtp = new SmptClient('http://mail-service.com', 'smtp_centra', 'fdr49nqwF$3r,>@3');
        $smtp->send(
          'Welcome to Centra Playground!',
          "Hey $name!
          
          Nice to have you onboard! This is your password in case you forget it: $password"
        );
    }
    
    public function grantAccess($username, $resource) {
        if ($this->isAdmin($username)) {
            // Grant access to resource
            echo "Access granted to $username for $resource.\n";
        } else {
            echo "Access denied for $username.\n";
        }
    }
}
Viewed 521 times, submitted by Guest.