metaregistrar / php-epp-client

Object-oriented PHP EPP Client
https://www.metaregistrar.com/docs/
MIT License
214 stars 159 forks source link

issue #260 fix wrong #261

Closed jansen-s closed 4 years ago

jansen-s commented 4 years ago

I have seen you fix this BUG, but your fix is wrong, which will cause the password update to be submitted when updating the contact. The correct fix is as follows:

        if ($postalInfo instanceof eppContactPostalInfo) {
            $this->addPostalInfo($postalInfo);
        } else {
            if (is_array($postalInfo)) {
                foreach ($postalInfo as $pi) {
                    if ($pi instanceof eppContactPostalInfo) {
                        $this->addPostalInfo($pi);
                    }
                }
            }
        }
        $this->setId($this->generateContactId());
        $this->setEmail($email);
        $this->setPassword($password);
        $this->setVoice($voice);
        $this->setFax($fax);
        $this->setStatus($status);
metaregistrar commented 4 years ago

hmm i have to fix this elsewhere i see. Because the generation of a default password is useful in some cases where registries require a contact to have a password but you don't want to be bothered generating it every time.

metaregistrar commented 4 years ago

I have now fixed the fix and generate a password (when none is set) upon eppCreateContactRequest

jansen-s commented 4 years ago

Well, you fixed the problem perfectly. In addition, I hope to give you a suggestion, you add symbols in the generateRandomString () method to strengthen the password strength. The following method is what I use now. This method can generate a strong password with a fixed length and containing 2-3 symbols.

protected function generatePassword(int $length=12){
        $alpha = ['a','b','c','d','e','f','g','h','j','k','m','n','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','J','K','M','N','P','Q','R','S','T','U','V','W','X','Y','Z'];
        $number = ['0','1','2','3','4','5','6','7','8','9'];
        $symbol = ['@','#','$','%','&','*','+','=','_','-','^','~'];
        $symbolNum = rand(2, 3);
        $charNum = ($length - $symbolNum) / 2;
        //打乱符号数组
        shuffle($symbol);
        shuffle($alpha);
        shuffle($number);
        //随机取字符
        $result['symbol'] = array_slice($symbol, 0, $symbolNum);
        $result['number'] = array_slice($number, 0, $charNum);
        $result['alpha'] = array_slice($alpha, 0, $length-$charNum-$symbolNum);
        //合并
        $password = array_merge([], $result['symbol'], $result['alpha'], $result['number']);
        shuffle($password);
        return implode('', $password);
    }