How to generate random password with PHP?

后端 未结 19 2108
栀梦
栀梦 2020-12-01 00:45

Or is there a software to auto generate random passwords?

相关标签:
19条回答
  • 2020-12-01 01:39

    use hackzilla/password-generator

    it has many options to create different kind of passwords:

    • ComputerPasswordGenerator()
    • HybridPasswordGenerator() -> sjgX-PFjH-zxMz-PRDz-G6mx-wMJ4-ST24
    • HumanPasswordGenerator() -> Verkuemmerungen-verlottertet-dreinzuschauen (word list based. in this case a german word list)
    • RequirementPasswordGenerator()

    ComputerPasswordGenerator

    $generator
      ->setOptionValue(ComputerPasswordGenerator::OPTION_UPPER_CASE, true)
      ->setOptionValue(ComputerPasswordGenerator::OPTION_LOWER_CASE, true)
      ->setOptionValue(ComputerPasswordGenerator::OPTION_NUMBERS, true)
      ->setOptionValue(ComputerPasswordGenerator::OPTION_SYMBOLS, false)
    ;
    
    $password = $generator->generatePassword();
    

    RequirementPasswordGenerator

    $generator
      ->setLength(16)
      ->setOptionValue(RequirementPasswordGenerator::OPTION_UPPER_CASE, true)
      ->setOptionValue(RequirementPasswordGenerator::OPTION_LOWER_CASE, true)
      ->setOptionValue(RequirementPasswordGenerator::OPTION_NUMBERS, true)
      ->setOptionValue(RequirementPasswordGenerator::OPTION_SYMBOLS, true)
      ->setMinimumCount(RequirementPasswordGenerator::OPTION_UPPER_CASE, 2)
      ->setMinimumCount(RequirementPasswordGenerator::OPTION_LOWER_CASE, 2)
      ->setMinimumCount(RequirementPasswordGenerator::OPTION_NUMBERS, 2)
      ->setMinimumCount(RequirementPasswordGenerator::OPTION_SYMBOLS, 2)
      ->setMaximumCount(RequirementPasswordGenerator::OPTION_UPPER_CASE, 8)
      ->setMaximumCount(RequirementPasswordGenerator::OPTION_LOWER_CASE, 8)
      ->setMaximumCount(RequirementPasswordGenerator::OPTION_NUMBERS, 8)
      ->setMaximumCount(RequirementPasswordGenerator::OPTION_SYMBOLS, 8)
    ;
    
    $password = $generator->generatePassword();
    
    0 讨论(0)
提交回复
热议问题