captainhook / secrets
Utility classes to detect secrets
Fund package maintenance!
sebastianfeldmann
Installs: 1 020 962
Dependents: 1
Suggesters: 0
Security: 0
Stars: 7
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: >=8.0
- ext-mbstring: *
README
This package is used to detect passwords in your code. Mainly to prevent you from committing them to your version control.
You can use the regular expressions provided by the classes under Regex\Supplier
or make use of the included Detector
class.
You can easily create your own Supplier
classes or open a pull-request if you think it would be useful to others.
Here are some usage examples:
Using Suppliers
$result = Detector::create() ->useSuppliers( Aws::class, Google::class, GitHub::class )->detectIn($myString) if ($result->wasSecretDetected()) { echo "secret detected: " . implode(' ', $result->matches()); }
Using your custom regex
$result = Detector::create() ->useRegex('#password = "\\S"#i') ->detectIn($myString) if ($result->wasSecretDetected()) { echo "secret detected: " . implode(' ', $result->matches()); }
The Detector
also supports a white list
$result = Detector::create() ->useRegex('#password = "\\S"#i') ->allow('#root#') ->detectIn($myString) if ($result->wasSecretDetected()) { echo "secret detected: " . implode(' ', $result->matches()); }