質問編集履歴
3
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -96,21 +96,23 @@
|
|
96
96
|
|
97
97
|
# パスワードを持っていないユーザーを取得してパスワード発行
|
98
98
|
|
99
|
-
$s
|
99
|
+
$sql = '
|
100
100
|
|
101
|
-
|
101
|
+
UPDATE users
|
102
102
|
|
103
|
-
|
103
|
+
SET pass = :pass
|
104
104
|
|
105
|
-
|
105
|
+
WHERE user_id = :user_id
|
106
106
|
|
107
|
-
|
107
|
+
';
|
108
108
|
|
109
|
-
$
|
109
|
+
$prepare = $dbn->prepare($sql);
|
110
110
|
|
111
|
-
$
|
111
|
+
$prepare->bindValue(':pass', $pass);
|
112
112
|
|
113
|
+
$prepare->bindValue(':user_id', '');
|
114
|
+
|
113
|
-
$
|
115
|
+
$prepare->execute();
|
114
116
|
|
115
117
|
```
|
116
118
|
|
2
内容の追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -22,15 +22,15 @@
|
|
22
22
|
|
23
23
|
|:--|:--|:--|
|
24
24
|
|
25
|
-
|1||
|
25
|
+
|1||ユーザー1|
|
26
26
|
|
27
|
-
|2||
|
27
|
+
|2||ユーザー2|
|
28
28
|
|
29
|
-
|3||
|
29
|
+
|3||ユーザー3|
|
30
30
|
|
31
|
-
|4||
|
31
|
+
|4||ユーザー4|
|
32
32
|
|
33
|
-
|5||
|
33
|
+
|5||ユーザー5|
|
34
34
|
|
35
35
|
|
36
36
|
|
@@ -40,15 +40,15 @@
|
|
40
40
|
|
41
41
|
|:--|:--|:--|
|
42
42
|
|
43
|
-
|1|123
|
43
|
+
|1|12345678|ユーザー1|
|
44
44
|
|
45
|
-
|2|123
|
45
|
+
|2|12345678|ユーザー2|
|
46
46
|
|
47
|
-
|3|123
|
47
|
+
|3|12345678|ユーザー3|
|
48
48
|
|
49
|
-
|4|123
|
49
|
+
|4|12345678|ユーザー4|
|
50
50
|
|
51
|
-
|5|123
|
51
|
+
|5|12345678|ユーザー5|
|
52
52
|
|
53
53
|
|
54
54
|
|
@@ -58,15 +58,15 @@
|
|
58
58
|
|
59
59
|
|:--|:--|:--|
|
60
60
|
|
61
|
-
|1|123
|
61
|
+
|1|12345678|ユーザー1|
|
62
62
|
|
63
|
-
|2|1234
|
63
|
+
|2|1234abcd|ユーザー2|
|
64
64
|
|
65
|
-
|3|abc
|
65
|
+
|3|abcd1234|ユーザー3|
|
66
66
|
|
67
|
-
|4|
|
67
|
+
|4|5678abcd|ユーザー4|
|
68
68
|
|
69
|
-
|5|
|
69
|
+
|5|abcdefgh|ユーザー5|
|
70
70
|
|
71
71
|
|
72
72
|
|
@@ -76,7 +76,7 @@
|
|
76
76
|
|
77
77
|
# パスワード発行用
|
78
78
|
|
79
|
-
$num =
|
79
|
+
$num = 8;
|
80
80
|
|
81
81
|
$ar1 = range('a','z');
|
82
82
|
|
@@ -113,3 +113,37 @@
|
|
113
113
|
$stmt->execute();
|
114
114
|
|
115
115
|
```
|
116
|
+
|
117
|
+
# 追記
|
118
|
+
|
119
|
+
これでランダム文字列をhash化して初期値の設定はできました。
|
120
|
+
|
121
|
+
```php
|
122
|
+
|
123
|
+
foreach($user as $user_id) {
|
124
|
+
|
125
|
+
$pass = substr(bin2hex(random_bytes($num)), 0, $num);
|
126
|
+
|
127
|
+
$hash = password_hash($pass, PASSWORD_BCRYPT);
|
128
|
+
|
129
|
+
$sql = '
|
130
|
+
|
131
|
+
UPDATE users
|
132
|
+
|
133
|
+
SET user_pw = :user_pw
|
134
|
+
|
135
|
+
WHERE user_id = :user_id
|
136
|
+
|
137
|
+
';
|
138
|
+
|
139
|
+
$prepare = $dbn->prepare($sql);
|
140
|
+
|
141
|
+
$prepare->bindValue(':user_pw', $hash);
|
142
|
+
|
143
|
+
$prepare->bindValue(':user_id', $user_id);
|
144
|
+
|
145
|
+
$prepare->execute();
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
```
|
1
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -102,13 +102,13 @@
|
|
102
102
|
|
103
103
|
SET `user_pw` = :pass
|
104
104
|
|
105
|
-
WHERE `user_
|
105
|
+
WHERE `user_pw` = :user_pw
|
106
106
|
|
107
107
|
');
|
108
108
|
|
109
|
-
$stmt->bind
|
109
|
+
$stmt->bindValue(':pass', $pass);
|
110
110
|
|
111
|
-
$stmt->bind
|
111
|
+
$stmt->bindValue(':user_pw', '');
|
112
112
|
|
113
113
|
$stmt->execute();
|
114
114
|
|