Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
outils
question2answer
Commits
0605eb99
Commit
0605eb99
authored
Jan 23, 2016
by
Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Coding style (new password hash code)
parent
b29c7635
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
41 deletions
+49
-41
install.php
qa-include/db/install.php
+5
-5
users.php
qa-include/db/users.php
+6
-6
account.php
qa-include/pages/account.php
+17
-14
login.php
qa-include/pages/login.php
+18
-15
qa-base.php
qa-include/qa-base.php
+3
-1
No files found.
qa-include/db/install.php
View file @
0605eb99
...
@@ -1460,13 +1460,13 @@
...
@@ -1460,13 +1460,13 @@
break
;
break
;
// Up to here: Version 1.8 alpha
case
62
:
case
62
:
qa_db_upgrade_query
(
'ALTER TABLE ^users ADD COLUMN passhash '
.
$definitions
[
'users'
][
'passhash'
]
.
' AFTER passcheck'
);
// add column to qa_users to handle new bcrypt passwords
qa_db_upgrade_query
(
$locktablesquery
);
qa_db_upgrade_query
(
'ALTER TABLE ^users ADD COLUMN passhash '
.
$definitions
[
'users'
][
'passhash'
]
.
' AFTER passcheck'
);
break
;
qa_db_upgrade_query
(
$locktablesquery
);
break
;
// Up to here: Version 1.8 alpha
}
}
qa_db_set_db_version
(
$newversion
);
qa_db_set_db_version
(
$newversion
);
...
...
qa-include/db/users.php
View file @
0605eb99
...
@@ -44,22 +44,22 @@
...
@@ -44,22 +44,22 @@
{
{
require_once
QA_INCLUDE_DIR
.
'util/string.php'
;
require_once
QA_INCLUDE_DIR
.
'util/string.php'
;
if
(
!
qa_php_version_below
(
'5.3.7'
))
{
if
(
!
qa_php_version_below
(
'5.3.7'
))
{
qa_db_query_sub
(
qa_db_query_sub
(
'INSERT INTO ^users (created, createip, email, passhash, level, handle, loggedin, loginip) '
.
'INSERT INTO ^users (created, createip, email, passhash, level, handle, loggedin, loginip) '
.
'VALUES (NOW(), COALESCE(INET_ATON($), 0), $, $, #, $, NOW(), COALESCE(INET_ATON($), 0))'
,
'VALUES (NOW(), COALESCE(INET_ATON($), 0), $, $, #, $, NOW(), COALESCE(INET_ATON($), 0))'
,
$ip
,
$email
,
isset
(
$password
)
?
password_hash
(
$password
,
PASSWORD_BCRYPT
)
:
null
,
(
int
)
$level
,
$handle
,
$ip
$ip
,
$email
,
isset
(
$password
)
?
password_hash
(
$password
,
PASSWORD_BCRYPT
)
:
null
,
(
int
)
$level
,
$handle
,
$ip
);
);
}
else
{
}
else
{
$salt
=
isset
(
$password
)
?
qa_random_alphanum
(
16
)
:
null
;
$salt
=
isset
(
$password
)
?
qa_random_alphanum
(
16
)
:
null
;
qa_db_query_sub
(
qa_db_query_sub
(
'INSERT INTO ^users (created, createip, email, passsalt, passcheck, level, handle, loggedin, loginip) '
.
'INSERT INTO ^users (created, createip, email, passsalt, passcheck, level, handle, loggedin, loginip) '
.
'VALUES (NOW(), COALESCE(INET_ATON($), 0), $, $, UNHEX($), #, $, NOW(), COALESCE(INET_ATON($), 0))'
,
'VALUES (NOW(), COALESCE(INET_ATON($), 0), $, $, UNHEX($), #, $, NOW(), COALESCE(INET_ATON($), 0))'
,
$ip
,
$email
,
$salt
,
isset
(
$password
)
?
qa_db_calc_passcheck
(
$password
,
$salt
)
:
null
,
(
int
)
$level
,
$handle
,
$ip
$ip
,
$email
,
$salt
,
isset
(
$password
)
?
qa_db_calc_passcheck
(
$password
,
$salt
)
:
null
,
(
int
)
$level
,
$handle
,
$ip
);
);
}
}
return
qa_db_last_insert_id
();
return
qa_db_last_insert_id
();
}
}
...
@@ -163,13 +163,13 @@
...
@@ -163,13 +163,13 @@
require_once
QA_INCLUDE_DIR
.
'util/string.php'
;
require_once
QA_INCLUDE_DIR
.
'util/string.php'
;
if
(
!
qa_php_version_below
(
'5.3.7'
))
{
if
(
!
qa_php_version_below
(
'5.3.7'
))
{
qa_db_query_sub
(
qa_db_query_sub
(
'UPDATE ^users SET passhash=$, passsalt=NULL, passcheck=NULL WHERE userid=$'
,
'UPDATE ^users SET passhash=$, passsalt=NULL, passcheck=NULL WHERE userid=$'
,
password_hash
(
$password
,
PASSWORD_BCRYPT
),
$userid
password_hash
(
$password
,
PASSWORD_BCRYPT
),
$userid
);
);
}
else
{
}
else
{
$salt
=
qa_random_alphanum
(
16
);
$salt
=
qa_random_alphanum
(
16
);
qa_db_query_sub
(
qa_db_query_sub
(
'UPDATE ^users SET passsalt=$, passcheck=UNHEX($) WHERE userid=$'
,
'UPDATE ^users SET passsalt=$, passcheck=UNHEX($) WHERE userid=$'
,
...
...
qa-include/pages/account.php
View file @
0605eb99
...
@@ -37,7 +37,7 @@
...
@@ -37,7 +37,7 @@
if
(
QA_FINAL_EXTERNAL_USERS
)
if
(
QA_FINAL_EXTERNAL_USERS
)
qa_fatal_error
(
'User accounts are handled by external code'
);
qa_fatal_error
(
'User accounts are handled by external code'
);
$userid
=
qa_get_logged_in_userid
();
$userid
=
qa_get_logged_in_userid
();
if
(
!
isset
(
$userid
))
if
(
!
isset
(
$userid
))
qa_redirect
(
'login'
);
qa_redirect
(
'login'
);
...
@@ -52,14 +52,15 @@
...
@@ -52,14 +52,15 @@
qa_db_userfields_selectspec
()
qa_db_userfields_selectspec
()
);
);
$changehandle
=
qa_opt
(
'allow_change_usernames'
)
||
((
!
$userpoints
[
'qposts'
])
&&
(
!
$userpoints
[
'aposts'
])
&&
(
!
$userpoints
[
'cposts'
]));
$changehandle
=
qa_opt
(
'allow_change_usernames'
)
||
(
!
$userpoints
[
'qposts'
]
&&
!
$userpoints
[
'aposts'
]
&&
!
$userpoints
[
'cposts'
]);
$doconfirms
=
qa_opt
(
'confirm_user_emails'
)
&&
(
$useraccount
[
'level'
]
<
QA_USER_LEVEL_EXPERT
);
$doconfirms
=
qa_opt
(
'confirm_user_emails'
)
&&
$useraccount
[
'level'
]
<
QA_USER_LEVEL_EXPERT
;
$isconfirmed
=
(
$useraccount
[
'flags'
]
&
QA_USER_FLAGS_EMAIL_CONFIRMED
)
?
true
:
false
;
$isconfirmed
=
(
$useraccount
[
'flags'
]
&
QA_USER_FLAGS_EMAIL_CONFIRMED
)
?
true
:
false
;
if
(
!
qa_php_version_below
(
'5.3.7'
)){
$haspasswordold
=
isset
(
$useraccount
[
'passsalt'
])
&&
isset
(
$useraccount
[
'passcheck'
]);
if
(
!
qa_php_version_below
(
'5.3.7'
))
{
$haspassword
=
isset
(
$useraccount
[
'passhash'
]);
$haspasswordold
=
isset
(
$useraccount
[
'passsalt'
])
&&
isset
(
$useraccount
[
'passcheck'
]);
$haspassword
=
isset
(
$useraccount
[
'passhash'
]);
}
else
{
}
else
{
$haspassword
=
isset
(
$useraccount
[
'passsalt'
])
&&
isset
(
$useraccount
[
'passcheck'
]);
$haspassword
=
isset
(
$useraccount
[
'passsalt'
])
&&
isset
(
$useraccount
[
'passcheck'
]);
}
}
$permit_error
=
qa_user_permit_error
();
$permit_error
=
qa_user_permit_error
();
$isblocked
=
$permit_error
!==
false
;
$isblocked
=
$permit_error
!==
false
;
...
@@ -209,16 +210,18 @@
...
@@ -209,16 +210,18 @@
else
{
else
{
$errors
=
array
();
$errors
=
array
();
if
(
!
qa_php_version_below
(
'5.3.7'
))
{
if
(
!
qa_php_version_below
(
'5.3.7'
))
{
if
(
if
(
(
$haspasswordold
&&
(
strtolower
(
qa_db_calc_passcheck
(
$inoldpassword
,
$useraccount
[
'passsalt'
]))
!=
strtolower
(
$useraccount
[
'passcheck'
])))
||
(
$haspasswordold
&&
(
strtolower
(
qa_db_calc_passcheck
(
$inoldpassword
,
$useraccount
[
'passsalt'
]))
!=
strtolower
(
$useraccount
[
'passcheck'
])))
||
(
!
$haspasswordold
&&
$haspassword
&&
!
password_verify
(
$inoldpassword
,
$useraccount
[
'passhash'
]))
(
!
$haspasswordold
&&
$haspassword
&&
!
password_verify
(
$inoldpassword
,
$useraccount
[
'passhash'
]))
)
)
{
$errors
[
'oldpassword'
]
=
qa_lang
(
'users/password_wrong'
);
$errors
[
'oldpassword'
]
=
qa_lang
(
'users/password_wrong'
);
}
}
else
{
}
else
{
if
(
$haspassword
&&
(
strtolower
(
qa_db_calc_passcheck
(
$inoldpassword
,
$useraccount
[
'passsalt'
]))
!=
strtolower
(
$useraccount
[
'passcheck'
])))
if
(
$haspassword
&&
(
strtolower
(
qa_db_calc_passcheck
(
$inoldpassword
,
$useraccount
[
'passsalt'
]))
!=
strtolower
(
$useraccount
[
'passcheck'
])))
{
$errors
[
'oldpassword'
]
=
qa_lang
(
'users/password_wrong'
);
$errors
[
'oldpassword'
]
=
qa_lang
(
'users/password_wrong'
);
}
}
}
$useraccount
[
'password'
]
=
$inoldpassword
;
$useraccount
[
'password'
]
=
$inoldpassword
;
...
...
qa-include/pages/login.php
View file @
0605eb99
...
@@ -67,47 +67,50 @@
...
@@ -67,47 +67,50 @@
if
(
count
(
$matchusers
)
==
1
)
{
// if matches more than one (should be impossible), don't log in
if
(
count
(
$matchusers
)
==
1
)
{
// if matches more than one (should be impossible), don't log in
$inuserid
=
$matchusers
[
0
];
$inuserid
=
$matchusers
[
0
];
$userinfo
=
qa_db_select_with_pending
(
qa_db_user_account_selectspec
(
$inuserid
,
true
));
$userinfo
=
qa_db_select_with_pending
(
qa_db_user_account_selectspec
(
$inuserid
,
true
));
if
(
!
qa_php_version_below
(
'5.3.7'
))
{
if
(
!
qa_php_version_below
(
'5.3.7'
))
{
$haspassword
=
isset
(
$userinfo
[
'passhash'
]);
$haspassword
=
isset
(
$userinfo
[
'passhash'
]);
$haspasswordold
=
isset
(
$userinfo
[
'passsalt'
])
&&
isset
(
$userinfo
[
'passcheck'
]);
$haspasswordold
=
isset
(
$userinfo
[
'passsalt'
])
&&
isset
(
$userinfo
[
'passcheck'
]);
if
(
if
(
(
$haspasswordold
&&
strtolower
(
qa_db_calc_passcheck
(
$inpassword
,
$userinfo
[
'passsalt'
]))
==
strtolower
(
$userinfo
[
'passcheck'
]))
||
(
$haspasswordold
&&
strtolower
(
qa_db_calc_passcheck
(
$inpassword
,
$userinfo
[
'passsalt'
]))
==
strtolower
(
$userinfo
[
'passcheck'
]))
||
(
$haspassword
&&
password_verify
(
$inpassword
,
$userinfo
[
'passhash'
]))
(
$haspassword
&&
password_verify
(
$inpassword
,
$userinfo
[
'passhash'
]))
)
{
// login and redirect
)
{
// login and redirect
require_once
QA_INCLUDE_DIR
.
'app/users.php'
;
require_once
QA_INCLUDE_DIR
.
'app/users.php'
;
// upgrade password or rehash, when options like the cost parameter changed
// upgrade password or rehash, when options like the cost parameter changed
if
(
$haspasswordold
||
password_needs_rehash
(
$userinfo
[
'passhash'
],
PASSWORD_BCRYPT
))
qa_db_user_set_password
(
$inuserid
,
$inpassword
);
if
(
$haspasswordold
||
password_needs_rehash
(
$userinfo
[
'passhash'
],
PASSWORD_BCRYPT
))
{
qa_db_user_set_password
(
$inuserid
,
$inpassword
);
}
qa_set_logged_in_user
(
$inuserid
,
$userinfo
[
'handle'
],
!
empty
(
$inremember
));
qa_set_logged_in_user
(
$inuserid
,
$userinfo
[
'handle'
],
!
empty
(
$inremember
));
$topath
=
qa_get
(
'to'
);
$topath
=
qa_get
(
'to'
);
if
(
isset
(
$topath
))
if
(
isset
(
$topath
))
qa_redirect_raw
(
qa_path_to_root
()
.
$topath
);
// path already provided as URL fragment
qa_redirect_raw
(
qa_path_to_root
()
.
$topath
);
// path already provided as URL fragment
elseif
(
$passwordsent
)
elseif
(
$passwordsent
)
qa_redirect
(
'account'
);
qa_redirect
(
'account'
);
else
else
qa_redirect
(
''
);
qa_redirect
(
''
);
}
else
}
else
$errors
[
'password'
]
=
qa_lang
(
'users/password_wrong'
);
$errors
[
'password'
]
=
qa_lang
(
'users/password_wrong'
);
}
else
{
}
else
{
if
(
strtolower
(
qa_db_calc_passcheck
(
$inpassword
,
$userinfo
[
'passsalt'
]))
==
strtolower
(
$userinfo
[
'passcheck'
]))
{
// login and redirect
if
(
strtolower
(
qa_db_calc_passcheck
(
$inpassword
,
$userinfo
[
'passsalt'
]))
==
strtolower
(
$userinfo
[
'passcheck'
]))
{
// login and redirect
require_once
QA_INCLUDE_DIR
.
'app/users.php'
;
require_once
QA_INCLUDE_DIR
.
'app/users.php'
;
qa_set_logged_in_user
(
$inuserid
,
$userinfo
[
'handle'
],
!
empty
(
$inremember
));
qa_set_logged_in_user
(
$inuserid
,
$userinfo
[
'handle'
],
!
empty
(
$inremember
));
$topath
=
qa_get
(
'to'
);
$topath
=
qa_get
(
'to'
);
if
(
isset
(
$topath
))
if
(
isset
(
$topath
))
qa_redirect_raw
(
qa_path_to_root
()
.
$topath
);
// path already provided as URL fragment
qa_redirect_raw
(
qa_path_to_root
()
.
$topath
);
// path already provided as URL fragment
elseif
(
$passwordsent
)
elseif
(
$passwordsent
)
qa_redirect
(
'account'
);
qa_redirect
(
'account'
);
else
else
qa_redirect
(
''
);
qa_redirect
(
''
);
}
else
}
else
$errors
[
'password'
]
=
qa_lang
(
'users/password_wrong'
);
$errors
[
'password'
]
=
qa_lang
(
'users/password_wrong'
);
}
}
...
...
qa-include/qa-base.php
View file @
0605eb99
...
@@ -77,7 +77,9 @@
...
@@ -77,7 +77,9 @@
qa_load_plugin_files
();
qa_load_plugin_files
();
qa_load_override_files
();
qa_load_override_files
();
if
(
!
qa_php_version_below
(
'5.3.7'
))
require_once
QA_INCLUDE_DIR
.
'vendor/password_compat.php'
;
if
(
!
qa_php_version_below
(
'5.3.7'
))
{
require_once
QA_INCLUDE_DIR
.
'vendor/password_compat.php'
;
}
require_once
QA_INCLUDE_DIR
.
'qa-db.php'
;
require_once
QA_INCLUDE_DIR
.
'qa-db.php'
;
qa_db_allow_connect
();
qa_db_allow_connect
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment