Skip to content

Commit

Permalink
Renaming and adding a composer file
Browse files Browse the repository at this point in the history
  • Loading branch information
Roderik van der Veer committed Sep 26, 2012
1 parent a36587c commit 5507d21
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
23 changes: 12 additions & 11 deletions pwgen.class.php → PWGen.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Port of the famous GNU/Linux Password Generator ("pwgen") to PHP.
* This file may be distributed under the terms of the GNU Public License.
Expand Down Expand Up @@ -193,7 +194,7 @@ private function pw_phonemes() {
$str = self::$elements[$i]->str;
$len = strlen($str);
$flags = self::$elements[$i]->flags;

// Filter on the basic type of the next element
if (($flags & $should_be) == 0)
continue;
Expand All @@ -207,13 +208,13 @@ private function pw_phonemes() {
// Don't allow us to overflow the buffer
if ($len > $this->pw_length-$c)
continue;

// Handle the AMBIGUOUS flag
if ($this->pwgen_flags & self::PW_AMBIGUOUS) {
if (strpbrk($str, self::$pw_ambiguous) !== false)
continue;
}

/*
* OK, we found an element which matches our criteria,
* let's do it!
Expand All @@ -228,13 +229,13 @@ private function pw_phonemes() {
$feature_flags &= ~self::PW_UPPERS;
}
}

$c += $len;

// Time to stop?
if ($c >= $this->pw_length)
break;

// Handle PW_DIGITS
if ($this->pwgen_flags & self::PW_DIGITS) {
if (!$first && (self::my_rand(0, 9) < 3)) {
Expand All @@ -244,14 +245,14 @@ private function pw_phonemes() {
strpos(self::$pw_ambiguous, $ch) !== false);
$this->password[$c++] = $ch;
$feature_flags &= ~self::PW_DIGITS;

$first = 1;
$prev = 0;
$should_be = self::my_rand(0, 1) ? self::VOWEL : self::CONSONANT;
continue;
}
}

// Handle PW_SYMBOLS
if ($this->pwgen_flags & self::PW_SYMBOLS) {
if (!$first && (self::my_rand(0, 9) < 2)) {
Expand All @@ -264,7 +265,7 @@ private function pw_phonemes() {
$feature_flags &= ~self::PW_SYMBOLS;
}
}

// OK, figure out what the next element should be
if ($should_be == self::CONSONANT) {
$should_be = self::VOWEL;
Expand Down Expand Up @@ -403,8 +404,8 @@ public function __toString() {

class PWElement {
public $str;
public $flags;
public $flags;

public function __construct($str, $flags) {
$this->str = $str;
$this->flags = $flags;
Expand Down
24 changes: 24 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "roderik/pwgen-php",
"type": "library",
"description": "pwgen-php is a simple PHP class which aims to clone the GNU pwgen functionality.",
"keywords": ["password", "generator"],
"license": "GPL",
"authors": [
{
"name": "Theodore Ts'o",
"email": "[email protected]"
},
{
"name": "Superwayne",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.3.3"
},
"autoload": {
"psr-0": { "PWGen": "" }
},
"target-dir": "PWGen"
}

0 comments on commit 5507d21

Please sign in to comment.