cancel
Showing results for 
Search instead for 
Did you mean: 

.htaccess password protection question

Mook
Seasoned Champion
Posts: 1,266
Thanks: 870
Fixes: 9
Registered: ‎27-12-2019

Re: .htaccess password protection question

I don't know if any of this is any use to you @shermans but if you adopt the random password generation approach I suggested above you can use the following code to create your password(s).


passgen.cpp
#include <iostream>
#include <random>

constexpr static std::string_view charMap("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()`~-_=+[{]}\\|;:'\",<.>/? ");

int main(int argc, char * * argv) try {
	int numIters{1} ;
	if (argc == 1) { std::cout << "Usage : " << argv[0] << " N I (Where N is the size of the password & I is the optional number of passwords required.)" << std::endl ; return EXIT_FAILURE ; }  
	if (argc == 3) numIters = std::atoi(argv[2]) ;
	const int pwdSize(std::atoi(argv[1])) ;
	if (pwdSize < Cool { std::cout << "Password length too small! Must be greater than 8" << std::endl ; return EXIT_FAILURE ; }
	std::random_device rd ;
	std::uniform_int_distribution< int > dist(0, charMap.size() -1) ; 
	for (int i{0}; i < numIters; i++) {
		for (int c{0}; c < pwdSize; c++) { std::cout << charMap[dist(rd)] ; }
		std::cout << std::endl ;
	}
	return EXIT_SUCCESS ;
} catch (std::exception const& e) {
	std::cerr << "Error " << e.what() << " in " << __func__ << std::endl ;
	return EXIT_FAILURE ;
}


You can compile the above using:

g++ -std=c++17 -Wall -Wpedantic -Wextra -fomit-frame-pointer -o pwg passgen.cpp


As it writes the output to std::cout your shell script can capture this allowing the password(s) generated to be used elsewhere within your script. Just remember and test the return value first to ensure its 0.

When the above is executed you'll get output similar to this:

Mook@iMac Development % ./pwg 16 10                                                                    
+T_xPt,0QST8Ujri
0~{cnU!LM=h^:sEh
J7Bt+'!c8"7B+\X!
<F]7/Q1!yU?6B,zQ
T{y!29\<`AUDc;=o
h#'?vV266a=A7,T~
sF,eXop"7;Can(EX
=n#Oyx$8qJP?wafX
:gwaB9%}ppJ9(~9?
15Css`OnoK/.)lav

 Generation of 10 passwords each of 16 chars in length

shermans
Pro
Posts: 1,303
Thanks: 101
Fixes: 3
Registered: ‎07-09-2007

Re: .htaccess password protection question

Thanks Mook.  That is really a great help.  I will certainly try it and let you know.

Mook
Seasoned Champion
Posts: 1,266
Thanks: 870
Fixes: 9
Registered: ‎27-12-2019

Re: .htaccess password protection question

This snippet of shell script to finish it off @shermans, and please don't think I'm teaching you to suck eggs I'm just trying to help.

#!/bin/zsh
PASSWDS=$(./pwg 16)
if [ $? -eq 0 ]; then
	echo -e "Password is : ${PASSWDS}"
else
	echo -e "Failed to generate password!"
fi

Outputs:

Mook@iMac Development % ./gen.sh
Password is : PR4jg}B!Y]o%yY`&

 

Mook
Seasoned Champion
Posts: 1,266
Thanks: 870
Fixes: 9
Registered: ‎27-12-2019

Re: .htaccess password protection question

Did you make any headway with this @shermans?

shermans
Pro
Posts: 1,303
Thanks: 101
Fixes: 3
Registered: ‎07-09-2007

Re: .htaccess password protection question

Mook

 

Just an update.  The matter is resolved, although it is not foolproof.  In Chrome, which is used on the computer in question, they have changed the settings 1. Offer to Save Passwords - OFF and 2. Auto-sign-in - OFF.  Then all that matters is that we remember to EXIT properly using the drop-down list on the right.  Quite simple and it works.

Of course, someone with access to the Chrome password could change those settings but it is unlikely.

So thanks to everyone who offered ideas.  The simplest solutions, like this one, of course are not always obvious !