<commit_before><?php

namespace ShipsUnburned\Service;

use Zend\Crypt\Password\Bcrypt;

/**
 * Service to verify and create salted passwords
 */
class PasswordService
{ 
    public $salt = '<KEY>';
    public $method = 'sha1';
    
    public function __construct($method = null)
    {
        if (! is_null($method))
        {
            $this->method = $method;
        }
    }
    /**
     * Generates a personalized salt
     * @param timestamp $timestamp
     */
    private function generateSalt($timestamp)
    {
        $saltTimesampt = sha1($this->salt . $timestamp);
        $this->salt = $this->salt . $saltTimesampt;
    }
    
    /**
     * Encrypts the password with the generated salt
     * 
     * @param string $password
     * @param timestamp $timestamp
     * @return string
     * 
     * TODO Integrate generateSalt()
     */
    public function create($password, $timestamp)
    {
        $this->generateSalt($timestamp);
        
        if ($this->method == 'md5')
        {
            return md5($this->salt . $password);
        }
        elseif ($this->method == 'sha1')
        {
            return sha1($this->salt . $password);
        }
        elseif ($this->method == 'bcrypt')
        {
            $bcrypt = new Bcrypt();
            $bcrypt->setCost(14);
            return $bcrypt->create($password);
        }
    }
    
    /**
     * Verifies if the password is correct
     * @param string $password
     * @param string $hash
     * @param timestamp timestamp
     * @return boolean
     * 
     * TODO: Integrate generateSalt()
     */
    public function verify($password, $hash, $timestamp)
    {
        $this->generateSalt($timestamp);
        
        if ($this->method == 'md5')
        {
            return $hash == md5($this->salt . $password);
        }
        elseif ($this->method == 'sha1')
        {
            return $hash = sha1($this->method == 'sha1');
        }
        elseif ($this->method == 'bcrypt')
        {<commit_msg>Added PasswordService, new column in tblUser and expanded the  Usermodel.<commit_after><?php

namespace ShipsUnburned\Service;

use Zend\Crypt\Password\Bcrypt;

/**
 * Service to verify and create salted passwords
 */
class PasswordService
{ 
    public $salt = '<KEY>';
    public $method = 'sha1';
    
    public function __construct($method = null)
    {
        if (! is_null($method))
        {
            $this->method = $method;
        }
    }
    /**
     * Generates a personalized salt
     * @param timestamp $timestamp
     */
    private function generateSalt($timestamp)
    {
        $saltTimesampt = sha1($this->salt . $timestamp);
        $this->salt = $this->salt . $saltTimesampt;
    }
    
    /**
     * Encrypts the password with the generated salt
     * 
     * @param string $password
     * @param timestamp $timestamp
     * @return string
     */
    public function create($password, $timestamp)
    {
        $this->generateSalt($timestamp);
        
        if ($this->method == 'md5')
        {
            return md5($this->salt . $password);
        }
        elseif ($this->method == 'sha1')
        {
            return sha1($this->salt . $password);
        }
        elseif ($this->method == 'bcrypt')
        {
            $bcrypt = new Bcrypt();
            $bcrypt->setCost(14);
            return $bcrypt->create($password);
        }
    }
    
    /**
     * Verifies if the password is correct
     * @param string $password
     * @param string $hash
     * @param timestamp timestamp
     * @return boolean
     */
    public function verify($password, $hash, $timestamp)
    {
        $this->generateSalt($timestamp);
        
        if ($this->method == 'md5')
        {
            return $hash == md5($this->salt . $password);
        }
        elseif ($this->method == 'sha1')
        {
            return $hash = sha1($this->method == 'sha1');
        }
        elseif ($this->method == 'bcrypt')
        {
{'fraction_non_alphanumeric': 0.13715584743622128, 'fraction_numerical': 0.006567314978529932, 'mean_word_length': 1.7808988764044944, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5563588', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1122, 'n_words': 265}