<?php
namespace ADAS\LogowanieBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* SysUsers
*/
class SysUsers implements UserInterface
{
/**
* @var string
*/
private $login;
/**
* @var string
*/
private $inicjaly;
/**
* @var string
*/
private $nazwisko;
/**
* @var string
*/
private $haslo;
/**
* @var \DateTime
*/
private $datahasla;
/**
* @var integer
*/
private $zmianahasla;
/**
* @var integer
*/
private $proby;
/**
* @var integer
*/
private $roles;
/**
* @var string
*/
private $zablokowany;
/**
* @var string
*/
private $pracowal;
/**
* @var \DateTime
*/
private $aktywnydo;
/**
* @var integer
*/
private $zrodlodanych;
/**
* @var integer
*/
private $zalozyl;
/**
* @var \DateTime
*/
private $datazal;
/**
* @var integer
*/
private $aktualizowal;
/**
* @var \DateTime
*/
private $dataakt;
/**
* @var integer
*/
private $id;
/**
* @var \ADAS\LogowanieBundle\Entity\SysOsoby
*/
private $idosoby;
/**
*
* @var string
*/
private $hasloZdekodowane;
/**
* @var string
*/
private $hasloMD5;
/**
* Stała wykorzystywana do dekodowania hasła
*/
const HEX_DIGITS = '0123456789ABCDEF';
const MD5_TAG = '(md5-a)';
/**
* @Soap\ComplexType("string")
* Sól wykorzystywana do kodowania hasła
*/
protected $salt = 'ORG-Service+> 2001+> Gdansk #10#09#0F#14#12#7#F#C#5#2';
/**
* Set login
*
* @param string $login
* @return SysUsers
*/
public function setLogin($login)
{
$this->login = $login;
return $this;
}
/**
* Get login
*
* @return string
*/
public function getLogin()
{
return $this->login;
}
/**
* Set inicjaly
*
* @param string $inicjaly
* @return SysUsers
*/
public function setInicjaly($inicjaly)
{
$this->inicjaly = $inicjaly;
return $this;
}
/**
* Get inicjaly
*
* @return string
*/
public function getInicjaly()
{
return $this->inicjaly;
}
/**
* Set nazwisko
*
* @param string $nazwisko
* @return SysUsers
*/
public function setNazwisko($nazwisko)
{
$this->nazwisko = $nazwisko;
return $this;
}
/**
* Get nazwisko
*
* @return string
*/
public function getNazwisko()
{
return $this->nazwisko;
}
/**
* Set haslo
*
* @param string $haslo
* @return SysUsers
*/
public function setHaslo($haslo)
{
$this->haslo = $haslo;
return $this;
}
/**
* Get haslo
*
* @return string
*/
public function getHaslo()
{
return $this->haslo;
}
/**
* Set datahasla
*
* @param \DateTime $datahasla
* @return SysUsers
*/
public function setDatahasla($datahasla)
{
$this->datahasla = $datahasla;
return $this;
}
/**
* Get datahasla
*
* @return \DateTime
*/
public function getDatahasla()
{
return $this->datahasla;
}
/**
* Set zmianahasla
*
* @param integer $zmianahasla
* @return SysUsers
*/
public function setZmianahasla($zmianahasla)
{
$this->zmianahasla = $zmianahasla;
return $this;
}
/**
* Get zmianahasla
*
* @return integer
*/
public function getZmianahasla()
{
return $this->zmianahasla;
}
/**
* Set proby
*
* @param integer $proby
* @return SysUsers
*/
public function setProby($proby)
{
$this->proby = $proby;
return $this;
}
/**
* Get proby
*
* @return integer
*/
public function getProby()
{
return $this->proby;
}
/**
* Set zablokowany
*
* @param string $zablokowany
* @return SysUsers
*/
public function setZablokowany($zablokowany)
{
$this->zablokowany = $zablokowany;
return $this;
}
/**
* Get zablokowany
*
* @return string
*/
public function getZablokowany()
{
return $this->zablokowany;
}
/**
* Set pracowal
*
* @param string $pracowal
* @return SysUsers
*/
public function setPracowal($pracowal)
{
$this->pracowal = $pracowal;
return $this;
}
/**
* Get pracowal
*
* @return string
*/
public function getPracowal()
{
return $this->pracowal;
}
/**
* Set aktywnydo
*
* @param \DateTime $aktywnydo
* @return SysUsers
*/
public function setAktywnydo($aktywnydo)
{
$this->aktywnydo = $aktywnydo;
return $this;
}
/**
* Get aktywnydo
*
* @return \DateTime
*/
public function getAktywnydo()
{
return $this->aktywnydo;
}
/**
* Set zrodlodanych
*
* @param integer $zrodlodanych
* @return SysUsers
*/
public function setZrodlodanych($zrodlodanych)
{
$this->zrodlodanych = $zrodlodanych;
return $this;
}
/**
* Get zrodlodanych
*
* @return integer
*/
public function getZrodlodanych()
{
return $this->zrodlodanych;
}
/**
* Set zalozyl
*
* @param integer $zalozyl
* @return SysUsers
*/
public function setZalozyl($zalozyl)
{
$this->zalozyl = $zalozyl;
return $this;
}
/**
* Get zalozyl
*
* @return integer
*/
public function getZalozyl()
{
return $this->zalozyl;
}
/**
* Set datazal
*
* @param \DateTime $datazal
* @return SysUsers
*/
public function setDatazalozenia($datazal)
{
$this->datazal = $datazal;
return $this;
}
/**
* Get datazal
*
* @return \DateTime
*/
public function getDatazalozenia()
{
return $this->datazal;
}
/**
* Set aktualizowal
*
* @param integer $aktualizowal
* @return SysUsers
*/
public function setAktualizowal($aktualizowal)
{
$this->aktualizowal = $aktualizowal;
return $this;
}
/**
* Get aktualizowal
*
* @return integer
*/
public function getAktualizowal()
{
return $this->aktualizowal;
}
/**
* Set dataakt
*
* @param \DateTime $dataakt
* @return SysUsers
*/
public function setDataaktualizacji($dataakt)
{
$this->dataakt = $dataakt;
return $this;
}
/**
* Get dataakt
*
* @return \DateTime
*/
public function getDataaktualizacji()
{
return $this->dataakt;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
if ($this->id === null) {
return 0;
}
else {
return $this->id;
}
}
/**
* Set idosoby
*
* @param \ADAS\LogowanieBundle\Entity\SysOsoby $idosoby
* @return SysUsers
*/
public function setIdosoby(\ADAS\LogowanieBundle\Entity\SysOsoby $idosoby = null)
{
$this->idosoby = $idosoby;
return $this;
}
/**
* Get idosoby
*
* @return \ADAS\LogowanieBundle\Entity\SysOsoby
*/
public function getIdosoby()
{
return $this->idosoby;
}
/**
*
* @param string $hasloZdekodowane
*
* return SysUsers
*/
public function setHaslozdekodowane($hasloZdekodowane)
{
$this->hasloZdekodowane=$hasloZdekodowane;
return $this;
}
/**
* zdekodowane hasło
* @return type
*/
public function getHaslozdekodowane()
{
//$this->konwertujHaslo();
return $this->hasloZdekodowane;
}
/**
*
* @param string $hasloMD5
*
* return SysUsers
*/
public function setHaslomd5($hasloMD5)
{
$this->hasloMD5=$hasloMD5;
return $this;
}
/**
* zdekodowane hasło
* @return type
*/
public function getHaslomd5()
{
//$this->konwertujHaslo();
return $this->hasloMD5;
}
/**
* @ORM\PostLoad
*/
public function konwertujHaslo()
{
if (strpos($this->haslo, $this::MD5_TAG) === 0) {
$this->hasloMD5 = str_replace($this::MD5_TAG, '', $this->haslo);
$this->salt = null;
}
else {
$this->hasloZdekodowane = $this->zdekoduj($this->haslo);
$this->hasloMD5 = md5($this->hasloZdekodowane.$this->salt);
}
}
/**
* Funkcje dekodujące hasło
*/
/**
* Funkcja dekodująca hasło
* @param type $string podajemy zakodowane hasło (jest w bazie)
* @return string odszyfrowane hasło
*/
public function zdekoduj($string) {
if ($string != '' && $string[0] == '<') {
$result = $this->Hex2Str(substr($string, 1, strlen($string) - 2));
$result = $this->OdSzyfrujStr($result);
if (strlen($result) == 0) {
return false;
}
$l = ord($result[strlen($result) - 1]);
$result = substr($result, strlen($result) - $l - 1, $l);
} else {
$result = $this->Hex2Str($string);
if (strlen($result) == 0) {
return false;
}
$result = $this->OdSzyfrujStr($result);
$result = substr($result, 1, ord($result[0]));
}
return $result;
}
public function zakoduj($string) {
if (strlen($string) == 0) return;
$result = $this->zaszyfrujStr($string);
if (strlen($result) == 0) return;
return '<' . $result . '>';
}
/**
* Funkcja pomocnicza w dekodowaniu hasła
* @param type $S
* @return type string
*/
private function Hex2Str($S) {
$N = '';
$RESULT = '';
for ($i = 0; $i < strlen($S); $i++) {
if (strpos(self::HEX_DIGITS, $S[$i]) !== false) {
$N.=$S[$i];
}
if ($N == '') {
continue;
}
if (strlen($N) == 2 || $i == strlen($S) || strpos(self::HEX_DIGITS, $S[$i]) === false) {
$RESULT.= chr(hexdec($N));
$N = '';
}
}
return $RESULT;
}
/**
* Funkcja pomocnicza w dekodowaniu hasła
* @param type $X
* @return type
*/
private function OdSzyfrujStr($X) {
$suma = 0;
$iK = 0;
$result = $X;
for ($iB = 0; $iB < strlen($result); $iB++) {
$tmp = $result[$iB];
$this->OdSzyfrujZnak($tmp, $suma, $iB + 1, $iK);
$result[$iB] = $tmp;
}
return $result;
}
private function zaszyfrujStr($X) {
$suma = 0;
$iK = 0;
$result = '';
$X .= chr(strlen($X));
while (strlen($X) < 24)
$X = chr(rand(32, 255)) . $X;
for ($iB = 0; $iB < strlen($X); $iB++) {
$tmp = ord($X[$iB]);
$this->zaszyfrujZnak($tmp, $suma, $iB + 1, $iK);
$result .= substr('0'.dechex($tmp), -2);
}
return strtoupper($result);
}
private function OdSzyfrujZnak(&$znak, &$suma, $iB, &$iK) {
$localKlucz = $this->salt;
$znak = ((ord($znak) ^ $suma) ^ $iB) - ord($localKlucz[$iK]);
$suma = $suma ^ $znak;
$iK++;
if ($iK > strlen($localKlucz)) {
$iK = 0;
}
$znak = chr($znak);
}
private function zaszyfrujZnak(&$znak, &$suma, $iB, &$iK) {
$localKlucz = $this->salt;
$przed = $znak;
$znak = (($znak + ord($localKlucz[$iK])) ^ $iB) ^ $suma;
$suma = $suma ^ $przed;
$iK++;
if ($iK > strlen($localKlucz)) {
$iK = 0;
}
}
public function getUsername() {
return $this->login;
}
public function getPassword() {
return $this->hasloMD5;
}
public function setRoles($roles)
{
$this->roles = $roles;
return $roles;
}
public function getRoles() {
return $this->roles;
}
public function addRoles(array $roles): static {
$this->roles = array_merge($this->roles,$roles);
return $this;
}
public function eraseCredentials() {
$this->haslo = null;
}
public function getSalt() {
return $this->salt;
}
public function __toString() {
return $this->login;
}
}