bundles/ADAS/LogowanieBundle/Entity/SysUsers.php line 11

Open in your IDE?
  1. <?php
  2. namespace ADAS\LogowanieBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\Security\Core\User\UserInterface;
  5. /**
  6.  * SysUsers
  7.  */
  8. class SysUsers implements UserInterface
  9. {
  10.     /**
  11.      * @var string
  12.      */
  13.     private $login;
  14.     /**
  15.      * @var string
  16.      */
  17.     private $inicjaly;
  18.     /**
  19.      * @var string
  20.      */
  21.     private $nazwisko;
  22.     /**
  23.      * @var string
  24.      */
  25.     private $haslo;
  26.     /**
  27.      * @var \DateTime
  28.      */
  29.     private $datahasla;
  30.     /**
  31.      * @var integer
  32.      */
  33.     private $zmianahasla;
  34.     /**
  35.      * @var integer
  36.      */
  37.     private $proby;
  38.     /**
  39.      * @var integer
  40.      */
  41.     private $roles;
  42.     /**
  43.      * @var string
  44.      */
  45.     private $zablokowany;
  46.     /**
  47.      * @var string
  48.      */
  49.     private $pracowal;
  50.     /**
  51.      * @var \DateTime
  52.      */
  53.     private $aktywnydo;
  54.     /**
  55.      * @var integer
  56.      */
  57.     private $zrodlodanych;
  58.     /**
  59.      * @var integer
  60.      */
  61.     private $zalozyl;
  62.     /**
  63.      * @var \DateTime
  64.      */
  65.     private $datazal;
  66.     /**
  67.      * @var integer
  68.      */
  69.     private $aktualizowal;
  70.     /**
  71.      * @var \DateTime
  72.      */
  73.     private $dataakt;
  74.   
  75.     /**
  76.      * @var integer
  77.      */
  78.     private $id;
  79.     /**
  80.      * @var \ADAS\LogowanieBundle\Entity\SysOsoby
  81.      */
  82.     private $idosoby;
  83.     /**
  84.      *
  85.      * @var string
  86.      */
  87.     private $hasloZdekodowane;
  88.     
  89.     /**
  90.      * @var string
  91.      */
  92.     private $hasloMD5;
  93.             
  94.         /**
  95.      * Stała wykorzystywana do dekodowania hasła
  96.      */
  97.     const HEX_DIGITS = '0123456789ABCDEF';    
  98.     
  99.     const MD5_TAG = '(md5-a)';
  100.     
  101.     /**
  102.      * @Soap\ComplexType("string")
  103.      * Sól wykorzystywana do kodowania hasła
  104.      */
  105.     protected $salt = 'ORG-Service+> 2001+> Gdansk #10#09#0F#14#12#7#F#C#5#2';
  106.     /**
  107.      * Set login
  108.      *
  109.      * @param string $login
  110.      * @return SysUsers
  111.      */
  112.     public function setLogin($login)
  113.     {
  114.         $this->login = $login;
  115.         return $this;
  116.     }
  117.     /**
  118.      * Get login
  119.      *
  120.      * @return string 
  121.      */
  122.     public function getLogin()
  123.     {
  124.         return $this->login;
  125.     }
  126.     /**
  127.      * Set inicjaly
  128.      *
  129.      * @param string $inicjaly
  130.      * @return SysUsers
  131.      */
  132.     public function setInicjaly($inicjaly)
  133.     {
  134.         $this->inicjaly = $inicjaly;
  135.         return $this;
  136.     }
  137.     /**
  138.      * Get inicjaly
  139.      *
  140.      * @return string 
  141.      */
  142.     public function getInicjaly()
  143.     {
  144.         return $this->inicjaly;
  145.     }
  146.     /**
  147.      * Set nazwisko
  148.      *
  149.      * @param string $nazwisko
  150.      * @return SysUsers
  151.      */
  152.     public function setNazwisko($nazwisko)
  153.     {
  154.         $this->nazwisko = $nazwisko;
  155.         return $this;
  156.     }
  157.     /**
  158.      * Get nazwisko
  159.      *
  160.      * @return string 
  161.      */
  162.     public function getNazwisko()
  163.     {
  164.         return $this->nazwisko;
  165.     }
  166.     /**
  167.      * Set haslo
  168.      *
  169.      * @param string $haslo
  170.      * @return SysUsers
  171.      */
  172.     public function setHaslo($haslo)
  173.     {
  174.         $this->haslo = $haslo;
  175.         return $this;
  176.     }
  177.     /**
  178.      * Get haslo
  179.      *
  180.      * @return string 
  181.      */
  182.     public function getHaslo()
  183.     {
  184.         return $this->haslo;
  185.     }
  186.     /**
  187.      * Set datahasla
  188.      *
  189.      * @param \DateTime $datahasla
  190.      * @return SysUsers
  191.      */
  192.     public function setDatahasla($datahasla)
  193.     {
  194.         $this->datahasla = $datahasla;
  195.         return $this;
  196.     }
  197.     /**
  198.      * Get datahasla
  199.      *
  200.      * @return \DateTime 
  201.      */
  202.     public function getDatahasla()
  203.     {
  204.         return $this->datahasla;
  205.     }
  206.     /**
  207.      * Set zmianahasla
  208.      *
  209.      * @param integer $zmianahasla
  210.      * @return SysUsers
  211.      */
  212.     public function setZmianahasla($zmianahasla)
  213.     {
  214.         $this->zmianahasla = $zmianahasla;
  215.         return $this;
  216.     }
  217.     /**
  218.      * Get zmianahasla
  219.      *
  220.      * @return integer 
  221.      */
  222.     public function getZmianahasla()
  223.     {
  224.         return $this->zmianahasla;
  225.     }
  226.     /**
  227.      * Set proby
  228.      *
  229.      * @param integer $proby
  230.      * @return SysUsers
  231.      */
  232.     public function setProby($proby)
  233.     {
  234.         $this->proby = $proby;
  235.         return $this;
  236.     }
  237.     /**
  238.      * Get proby
  239.      *
  240.      * @return integer 
  241.      */
  242.     public function getProby()
  243.     {
  244.         return $this->proby;
  245.     }
  246.     /**
  247.      * Set zablokowany
  248.      *
  249.      * @param string $zablokowany
  250.      * @return SysUsers
  251.      */
  252.     public function setZablokowany($zablokowany)
  253.     {
  254.         $this->zablokowany = $zablokowany;
  255.         return $this;
  256.     }
  257.     /**
  258.      * Get zablokowany
  259.      *
  260.      * @return string 
  261.      */
  262.     public function getZablokowany()
  263.     {
  264.         return $this->zablokowany;
  265.     }
  266.     /**
  267.      * Set pracowal
  268.      *
  269.      * @param string $pracowal
  270.      * @return SysUsers
  271.      */
  272.     public function setPracowal($pracowal)
  273.     {
  274.         $this->pracowal = $pracowal;
  275.         return $this;
  276.     }
  277.     /**
  278.      * Get pracowal
  279.      *
  280.      * @return string 
  281.      */
  282.     public function getPracowal()
  283.     {
  284.         return $this->pracowal;
  285.     }
  286.     /**
  287.      * Set aktywnydo
  288.      *
  289.      * @param \DateTime $aktywnydo
  290.      * @return SysUsers
  291.      */
  292.     public function setAktywnydo($aktywnydo)
  293.     {
  294.         $this->aktywnydo = $aktywnydo;
  295.         return $this;
  296.     }
  297.     /**
  298.      * Get aktywnydo
  299.      *
  300.      * @return \DateTime 
  301.      */
  302.     public function getAktywnydo()
  303.     {
  304.         return $this->aktywnydo;
  305.     }
  306.     /**
  307.      * Set zrodlodanych
  308.      *
  309.      * @param integer $zrodlodanych
  310.      * @return SysUsers
  311.      */
  312.     public function setZrodlodanych($zrodlodanych)
  313.     {
  314.         $this->zrodlodanych = $zrodlodanych;
  315.         return $this;
  316.     }
  317.     /**
  318.      * Get zrodlodanych
  319.      *
  320.      * @return integer 
  321.      */
  322.     public function getZrodlodanych()
  323.     {
  324.         return $this->zrodlodanych;
  325.     }
  326.     /**
  327.      * Set zalozyl
  328.      *
  329.      * @param integer $zalozyl
  330.      * @return SysUsers
  331.      */
  332.     public function setZalozyl($zalozyl)
  333.     {
  334.         $this->zalozyl = $zalozyl;
  335.         return $this;
  336.     }
  337.     /**
  338.      * Get zalozyl
  339.      *
  340.      * @return integer 
  341.      */
  342.     public function getZalozyl()
  343.     {
  344.         return $this->zalozyl;
  345.     }
  346.     /**
  347.      * Set datazal
  348.      *
  349.      * @param \DateTime $datazal
  350.      * @return SysUsers
  351.      */
  352.     public function setDatazalozenia($datazal)
  353.     {
  354.         $this->datazal = $datazal;
  355.         return $this;
  356.     }
  357.     /**
  358.      * Get datazal
  359.      *
  360.      * @return \DateTime 
  361.      */
  362.     public function getDatazalozenia()
  363.     {
  364.         return $this->datazal;
  365.     }
  366.     /**
  367.      * Set aktualizowal
  368.      *
  369.      * @param integer $aktualizowal
  370.      * @return SysUsers
  371.      */
  372.     public function setAktualizowal($aktualizowal)
  373.     {
  374.         $this->aktualizowal = $aktualizowal;
  375.         return $this;
  376.     }
  377.     /**
  378.      * Get aktualizowal
  379.      *
  380.      * @return integer 
  381.      */
  382.     public function getAktualizowal()
  383.     {
  384.         return $this->aktualizowal;
  385.     }
  386.     /**
  387.      * Set dataakt
  388.      *
  389.      * @param \DateTime $dataakt
  390.      * @return SysUsers
  391.      */
  392.     public function setDataaktualizacji($dataakt)
  393.     {
  394.         $this->dataakt = $dataakt;
  395.         return $this;
  396.     }
  397.     /**
  398.      * Get dataakt
  399.      *
  400.      * @return \DateTime 
  401.      */
  402.     public function getDataaktualizacji()
  403.     {
  404.         return $this->dataakt;
  405.     }
  406.     /**
  407.      * Get id
  408.      *
  409.      * @return integer 
  410.      */
  411.     public function getId()
  412.     {
  413.         if ($this->id === null) {
  414.             return 0;
  415.         }
  416.         else {
  417.             return $this->id;
  418.         }
  419.     }
  420.     /**
  421.      * Set idosoby
  422.      *
  423.      * @param \ADAS\LogowanieBundle\Entity\SysOsoby $idosoby
  424.      * @return SysUsers
  425.      */
  426.     public function setIdosoby(\ADAS\LogowanieBundle\Entity\SysOsoby $idosoby = null)
  427.     {
  428.         $this->idosoby = $idosoby;
  429.         return $this;
  430.     }
  431.     /**
  432.      * Get idosoby
  433.      *
  434.      * @return \ADAS\LogowanieBundle\Entity\SysOsoby 
  435.      */
  436.     public function getIdosoby()
  437.     {
  438.         return $this->idosoby;
  439.     }
  440.     /**
  441.      * 
  442.      * @param string $hasloZdekodowane
  443.      * 
  444.      * return SysUsers
  445.      */
  446.     public function setHaslozdekodowane($hasloZdekodowane)
  447.     {
  448.         $this->hasloZdekodowane=$hasloZdekodowane;
  449.         return $this;
  450.     }
  451.     
  452.     /**
  453.      *  zdekodowane hasło
  454.      * @return type
  455.      */
  456.     public function getHaslozdekodowane()
  457.     {
  458.         //$this->konwertujHaslo();
  459.         return $this->hasloZdekodowane;
  460.     }  
  461.     
  462.     
  463.     /**
  464.      * 
  465.      * @param string $hasloMD5
  466.      * 
  467.      * return SysUsers
  468.      */
  469.     public function setHaslomd5($hasloMD5)
  470.     {
  471.         $this->hasloMD5=$hasloMD5;
  472.         return $this;
  473.     }
  474.     
  475.     /**
  476.      *  zdekodowane hasło
  477.      * @return type
  478.      */
  479.     public function getHaslomd5()
  480.     {
  481.         //$this->konwertujHaslo();
  482.         return $this->hasloMD5;
  483.     }        
  484.     
  485.     /**
  486.      * @ORM\PostLoad
  487.      */
  488.     public function konwertujHaslo()
  489.     {
  490.         if (strpos($this->haslo, $this::MD5_TAG) === 0) { 
  491.             $this->hasloMD5 = str_replace($this::MD5_TAG, '', $this->haslo);
  492.             $this->salt = null;
  493.         }    
  494.         else {
  495.             $this->hasloZdekodowane = $this->zdekoduj($this->haslo);
  496.             $this->hasloMD5 = md5($this->hasloZdekodowane.$this->salt);
  497.         }
  498.     }
  499.     
  500.   /**
  501.      * Funkcje dekodujące hasło
  502.      */
  503.     
  504.     /**
  505.      * Funkcja dekodująca hasło 
  506.      * @param type $string podajemy zakodowane hasło (jest w bazie)
  507.      * @return string odszyfrowane hasło
  508.      */
  509.     public function zdekoduj($string) {
  510.         if ($string != '' && $string[0] == '<') {
  511.             $result = $this->Hex2Str(substr($string, 1, strlen($string) - 2));
  512.             $result = $this->OdSzyfrujStr($result);
  513.             if (strlen($result) == 0) {
  514.                 return false;
  515.             }
  516.             $l = ord($result[strlen($result) - 1]);
  517.             $result = substr($result, strlen($result) - $l - 1, $l);
  518.         } else {
  519.             $result = $this->Hex2Str($string);
  520.             if (strlen($result) == 0) {
  521.                 return false;
  522.             }
  523.             $result = $this->OdSzyfrujStr($result);
  524.             $result = substr($result, 1, ord($result[0]));
  525.         }
  526.         return $result;
  527.     }
  528.     
  529.     public function zakoduj($string) {
  530.         
  531.         if (strlen($string) == 0) return;
  532.         $result = $this->zaszyfrujStr($string);
  533.             
  534.         if (strlen($result) == 0) return;
  535.         return '<' . $result . '>';
  536.     }
  537.     
  538.     
  539.     /**
  540.      * Funkcja pomocnicza w dekodowaniu hasła
  541.      * @param type $S
  542.      * @return type string
  543.      */
  544.      private function Hex2Str($S) {
  545.         $N = '';
  546.         $RESULT = '';
  547.         for ($i = 0; $i < strlen($S); $i++) {
  548.             if (strpos(self::HEX_DIGITS, $S[$i]) !== false) {
  549.                 $N.=$S[$i];
  550.             }
  551.             if ($N == '') {
  552.                 continue;
  553.             }
  554.             if (strlen($N) == 2 || $i == strlen($S) || strpos(self::HEX_DIGITS, $S[$i]) === false) {
  555.                 $RESULT.= chr(hexdec($N));
  556.                 $N = '';
  557.             }
  558.         }
  559.         return $RESULT;
  560.     }
  561.     
  562.     /**
  563.      * Funkcja pomocnicza w dekodowaniu hasła
  564.      * @param type $X
  565.      * @return type
  566.      */
  567.      private function OdSzyfrujStr($X) {
  568.         $suma = 0;
  569.         $iK = 0;
  570.         $result = $X;
  571.         for ($iB = 0; $iB < strlen($result); $iB++) {
  572.             $tmp = $result[$iB];
  573.             $this->OdSzyfrujZnak($tmp, $suma, $iB + 1, $iK);
  574.             $result[$iB] = $tmp;
  575.         }
  576.         return $result;
  577.     }
  578.     
  579.     private function zaszyfrujStr($X) {
  580.         $suma = 0;
  581.         $iK = 0;
  582.         $result = '';
  583.         $X .= chr(strlen($X)); 
  584.         while (strlen($X) < 24)
  585.             $X = chr(rand(32, 255)) . $X;    
  586.         
  587.         for ($iB = 0; $iB < strlen($X); $iB++) {
  588.             $tmp = ord($X[$iB]);
  589.             $this->zaszyfrujZnak($tmp, $suma, $iB + 1, $iK);
  590.             $result .= substr('0'.dechex($tmp), -2);
  591.         }
  592.         
  593.         return strtoupper($result);
  594.     }
  595.     
  596.      private function OdSzyfrujZnak(&$znak, &$suma, $iB, &$iK) {
  597.         $localKlucz = $this->salt;
  598.         $znak = ((ord($znak) ^ $suma) ^ $iB) - ord($localKlucz[$iK]);
  599.         $suma = $suma ^ $znak;
  600.         $iK++;
  601.         if ($iK > strlen($localKlucz)) {
  602.             $iK = 0;
  603.         }
  604.         $znak = chr($znak);
  605.     }
  606.     private function zaszyfrujZnak(&$znak, &$suma, $iB, &$iK) {
  607.     
  608.         $localKlucz = $this->salt;
  609.         $przed = $znak;
  610.         $znak = (($znak + ord($localKlucz[$iK])) ^ $iB) ^ $suma;
  611.         $suma = $suma ^ $przed;
  612.         $iK++;
  613.         if ($iK > strlen($localKlucz)) {
  614.             $iK = 0;
  615.         }
  616.     }
  617.     
  618.      public function getUsername() {
  619.         return $this->login;
  620.     }
  621.     
  622.     public function getPassword() {
  623.         return $this->hasloMD5;
  624.     }
  625.     
  626.     public function setRoles($roles)
  627.     {
  628.         $this->roles = $roles;
  629.         return $roles;
  630.     }
  631.     public function getRoles() {
  632.         return $this->roles;
  633.     }
  634.     
  635.     public function addRoles(array $roles): static {
  636.        $this->roles = array_merge($this->roles,$roles);
  637.        return $this;
  638.     }
  639.     
  640.     public function eraseCredentials() {
  641.         $this->haslo = null;
  642.     }
  643.     
  644.     public function getSalt() {
  645.         return $this->salt;
  646.     }
  647.     public function __toString() {
  648.         return $this->login;
  649.     }
  650. }