xref: /PHP-8.2/ext/oci8/tests/password_2.phpt (revision 74859783)
1--TEST--
2oci_password_change() for persistent connections
3--EXTENSIONS--
4oci8
5--SKIPIF--
6<?php
7require(__DIR__."/details.inc");
8if (empty($dbase)) die ("skip requires database connection string be set");
9if (strcasecmp($user, "system") && strcasecmp($user, "sys")) die("skip needs to be run as a DBA user");
10if ($test_drcp) die("skip password change not supported in DRCP Mode");
11?>
12--FILE--
13<?php
14
15require(__DIR__."/connect.inc");
16
17$stmtarray = array(
18    "drop user testuser_pw2 cascade",
19    "create user testuser_pw2 identified by testuserpwd",
20    "grant connect, create session to testuser_pw2"
21);
22
23oci8_test_sql_execute($c, $stmtarray);
24
25// Connect (persistent) and change the password
26$c1 = oci_pconnect("testuser_pw2", "testuserpwd", $dbase);
27var_dump($c1);
28$rn1 = (int)$c1;
29
30oci_password_change($c1, "testuser_pw2", "testuserpwd", "testuserpwd2");
31
32// Second connect should return a new resource because the hash string will be different from $c1
33$c2 = oci_pconnect("testuser_pw2", "testuserpwd2", $dbase);
34var_dump($c2);
35$rn2 = (int)$c2;
36
37// Despite using the old password this connect should succeed and return the original resource
38$c3 = oci_pconnect("testuser_pw2", "testuserpwd", $dbase);
39var_dump($c3);
40$rn3 = (int)$c3;
41
42// Connections should differ
43if ($rn1 == $rn2) {
44    echo "First and second connections share a resource: Not OK\n";
45    var_dump($c1);
46}
47else {
48    echo "First and second connections are different: OK\n";
49}
50
51// Connections should be the same
52if ($rn1 == $rn3) {
53    echo "First and third connections share a resource: OK\n";
54}
55else {
56    echo "First and third connections are different: Not OK\n";
57    var_dump($c1);
58    var_dump($c2);
59}
60
61echo "Done\n";
62
63?>
64--CLEAN--
65<?php
66
67require(__DIR__."/connect.inc");
68
69$stmtarray = array(
70    "drop user testuser_pw2 cascade"
71);
72
73oci8_test_sql_execute($c, $stmtarray);
74
75?>
76--EXPECTF--
77resource(%d) of type (oci8 persistent connection)
78resource(%d) of type (oci8 persistent connection)
79resource(%d) of type (oci8 persistent connection)
80First and second connections are different: OK
81First and third connections share a resource: OK
82Done
83