lrkrol / Noctifer-Music

PHP HTML5 music player for self-hosted online libraries
GNU General Public License v3.0
56 stars 16 forks source link

Update Index.php - Password Array / Multiple Password Support #13

Closed MassInsanity closed 1 year ago

MassInsanity commented 1 year ago

Update Index.php - Password Array / Multiple Password Support changes made for version 0.7.3 of Noctifer-Music

lrkrol commented 1 year ago

Hey, thanks for the PR! I appreciate the functionality: I assume the intended use case for this is to easily allow (or revoke) others access to it with their own password?

Theoretically, I do not believe foreach is the most appropriate implementation for such a thing. I would rather suggest to simply replace the original line where the password is checked,

if ( htmlspecialchars($password) == htmlspecialchars( $_POST['password'] ) ) {

with the following which checks if the given password is to be found in the array rather than looping through it:

if ( in_array( htmlspecialchars( $_POST['password'] ), array_map( 'htmlspecialchars', $passwords ), true ) ) {

Note I would then also change the array name to plural $passwords, i.e.:

# whether or not to ask for a password, and if yes, the array of allowed passwords to access directory/playlist contents
$usepassword = true;
$passwords = array('123', '234');
MassInsanity commented 1 year ago

agreed. And yes- this allows you the ability to provide different people different passwords and add/delete access as such.

lrkrol commented 1 year ago

Thanks! Sounds good. Would you like to update the PR or shall I make the changes directly in the master branch?

MassInsanity commented 1 year ago

If you wouldn't mind committing it to the master, that'd be great. I'm still new to Github, trying to learn how this all works. :)

lrkrol commented 1 year ago

Done now -- thanks again!