summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRemi Collet <remi@remirepo.net>2024-08-27 10:50:21 +0200
committerRemi Collet <remi@php.net>2024-08-27 10:50:21 +0200
commitd4ff70e6cd95010bbe47f9a5a81a19bdae52e241 (patch)
tree3271a8fee984854524f79987cdcf21e3d6289fe6 /tests
parent1c8bfa97ff1976f212b07e3dc30b78eac60b253d (diff)
start development
Diffstat (limited to 'tests')
-rw-r--r--tests/sha512.phpt93
-rw-r--r--tests/xpass.phpt10
-rw-r--r--tests/yescrypt.phpt92
3 files changed, 195 insertions, 0 deletions
diff --git a/tests/sha512.phpt b/tests/sha512.phpt
new file mode 100644
index 0000000..2a91456
--- /dev/null
+++ b/tests/sha512.phpt
@@ -0,0 +1,93 @@
+--TEST--
+Check if xpass is loaded
+--EXTENSIONS--
+xpass
+--SKIPIF--
+<?php
+if (!defined("PASSWORD_SHA512")) die("skip SHA512 missing");
+?>
+--FILE--
+<?php
+$data = [
+ 'mysecret' => '$6$1w/SLyhyEvGAul3q$W5VyKdQFPZaNOoIWMJTIi590Tu7ioejI90F0asQneP/Mn893X0m3aPIb2J7I4cPXtuN65t/vNwgMGHlfvf6hK/',
+ 'remicollet' => '$6$BG/h0.OlUBaXdi11$iJnP3HmoR3QicxajlNTgGPpLBEDAe/QTpcrNPPZJwcc.orIwvTPQK5E5IjPmIu2ArLj3mjjVGDUSRNgDb32jD.',
+];
+foreach($data as $pass => $hash) {
+ echo "-- $pass\n";
+ var_dump(password_verify($pass, $hash));
+ var_dump(password_get_info($hash));
+ var_dump(password_verify($pass."bad", $hash));
+ var_dump(password_verify($pass, $hash."bad"));
+ var_dump(password_needs_rehash($hash, PASSWORD_SHA512));
+}
+
+echo "-- no cost\n";
+$pass = 'secret';
+var_dump($hash = password_hash($pass, PASSWORD_SHA512));
+var_dump(password_get_info($hash));
+var_dump(password_verify($pass, $hash));
+foreach([0,4,8,99] as $cost) {
+ echo "-- cost=$cost\n";
+ try {
+ $pass = "secret$cost";
+ var_dump($hash = password_hash($pass, PASSWORD_SHA512, ['cost'=>$cost]));
+ var_dump(password_verify($pass, $hash));
+ } catch (ValueError $e) {
+ printf("EXCEPTION %s\n", $e->getMessage());
+ }
+}
+?>
+--EXPECTF--
+-- mysecret
+bool(true)
+array(3) {
+ ["algo"]=>
+ string(1) "6"
+ ["algoName"]=>
+ string(6) "sha512"
+ ["options"]=>
+ array(0) {
+ }
+}
+bool(false)
+bool(false)
+bool(false)
+-- remicollet
+bool(true)
+array(3) {
+ ["algo"]=>
+ string(1) "6"
+ ["algoName"]=>
+ string(6) "sha512"
+ ["options"]=>
+ array(0) {
+ }
+}
+bool(false)
+bool(false)
+bool(false)
+-- no cost
+string(106) "$6$%s"
+array(3) {
+ ["algo"]=>
+ string(1) "6"
+ ["algoName"]=>
+ string(6) "sha512"
+ ["options"]=>
+ array(0) {
+ }
+}
+bool(true)
+-- cost=0
+string(106) "$6$%s"
+bool(true)
+-- cost=4
+string(118) "$6$rounds=1000$%s"
+bool(true)
+-- cost=8
+string(118) "$6$rounds=1000$%s"
+bool(true)
+-- cost=99
+string(118) "$6$rounds=1000$%s"
+bool(true)
+
diff --git a/tests/xpass.phpt b/tests/xpass.phpt
new file mode 100644
index 0000000..e30ce54
--- /dev/null
+++ b/tests/xpass.phpt
@@ -0,0 +1,10 @@
+--TEST--
+Check if xpass is loaded
+--EXTENSIONS--
+xpass
+--FILE--
+<?php
+echo 'The extension "xpass" is available';
+?>
+--EXPECT--
+The extension "xpass" is available
diff --git a/tests/yescrypt.phpt b/tests/yescrypt.phpt
new file mode 100644
index 0000000..38c84e2
--- /dev/null
+++ b/tests/yescrypt.phpt
@@ -0,0 +1,92 @@
+--TEST--
+Check if xpass is loaded
+--EXTENSIONS--
+xpass
+--SKIPIF--
+<?php
+if (!defined("PASSWORD_YESCRYPT")) die("skip YESCRYPT missing");
+?>
+--FILE--
+<?php
+$data = [
+ 'mysecret' => '$y$j9T$EWkxmhFdtlCH.UrDi8l6T1$65TpODO1HXFLut3PhZhxiFweWNWFpo7QHTQtMVanr2B',
+ 'remicollet' => '$y$j9T$XxuuhBKq0UT68HX8KXaXy0$p.PggRtVfQ6rO5TReD0TgMKFyfNEA2l3QQi/dW8fS63',
+];
+foreach($data as $pass => $hash) {
+ echo "-- $pass\n";
+ var_dump(password_verify($pass, $hash));
+ var_dump(password_get_info($hash));
+ var_dump(password_verify($pass."bad", $hash));
+ var_dump(password_verify($pass, $hash."bad"));
+ var_dump(password_needs_rehash($hash, PASSWORD_YESCRYPT));
+}
+
+echo "-- no cost\n";
+$pass = 'secret';
+var_dump($hash = password_hash($pass, PASSWORD_YESCRYPT));
+var_dump(password_get_info($hash));
+var_dump(password_verify($pass, $hash));
+foreach([0,4,8,99] as $cost) {
+ echo "-- cost=$cost\n";
+ try {
+ $pass = "secret$cost";
+ var_dump($hash = password_hash($pass, PASSWORD_YESCRYPT, ['cost'=>$cost]));
+ var_dump(password_verify($pass, $hash));
+ } catch (ValueError $e) {
+ printf("EXCEPTION %s\n", $e->getMessage());
+ }
+}
+?>
+--EXPECTF--
+-- mysecret
+bool(true)
+array(3) {
+ ["algo"]=>
+ string(1) "y"
+ ["algoName"]=>
+ string(8) "yescrypt"
+ ["options"]=>
+ array(0) {
+ }
+}
+bool(false)
+bool(false)
+bool(false)
+-- remicollet
+bool(true)
+array(3) {
+ ["algo"]=>
+ string(1) "y"
+ ["algoName"]=>
+ string(8) "yescrypt"
+ ["options"]=>
+ array(0) {
+ }
+}
+bool(false)
+bool(false)
+bool(false)
+-- no cost
+string(73) "$y$j9T$%s"
+array(3) {
+ ["algo"]=>
+ string(1) "y"
+ ["algoName"]=>
+ string(8) "yescrypt"
+ ["options"]=>
+ array(0) {
+ }
+}
+bool(true)
+-- cost=0
+string(73) "$y$j9T$%s"
+bool(true)
+-- cost=4
+string(73) "$y$j8T$%s"
+bool(true)
+-- cost=8
+string(73) "$y$jCT$%s"
+bool(true)
+-- cost=99
+EXCEPTION Bad password options
+