@@ -247,7 +247,7 @@ std::string BlogSystem::generate_salt(int length) {
247247 7 , 0x9d2c5680 ,
248248 15 , 0xefc60000 ,
249249 18 , 1812433253 > generator (random_value);
250- const std::uniform_int_distribution<std::string::size_type> pick (0 , sizeof (chrs) - 2 );
250+ std::uniform_int_distribution<std::string::size_type> pick (0 , sizeof (chrs) - 2 );
251251
252252 std::string random_str;
253253
@@ -1019,50 +1019,52 @@ int BlogSystem::delete_post(std::string post_id)
10191019
10201020
10211021int BlogSystem::hash_password (char *dst, const char *passphrase, uint32_t N, uint8_t r, uint8_t p) {
1022- try {
1023- uint8_t salt[SCRYPT_SALT_LEN] = {};
1024- uint8_t hashbuf[SCRYPT_HASH_LEN];
1025- char outbuf[256 ];
1026- char saltbuf[256 ];
1022+ uint8_t salt[SCRYPT_SALT_LEN] = {};
1023+ uint8_t hashbuf[SCRYPT_HASH_LEN];
1024+ char outbuf[256 ];
1025+ char saltbuf[256 ];
10271026
1028- std::string generatedSalt = generate_salt (SCRYPT_SALT_LEN);
1029- if (generatedSalt == " " )
1030- {
1031- throw std::exception (" generateSalt error..." );
1032- }
1033-
1034- copy (generatedSalt.begin (), generatedSalt.end (), salt);
1035- salt[generatedSalt.length () - 1 ] = 0 ;
1027+ std::string generatedSalt = generate_salt (SCRYPT_SALT_LEN);
1028+ if (generatedSalt == " " )
1029+ {
1030+ std::cout << " [ " << " generateSalt error..." << " ]" ;
1031+ return 0 ;
1032+ }
10361033
1037- auto retval = libscrypt_scrypt (reinterpret_cast <const uint8_t *>(passphrase), strlen (passphrase),
1038- static_cast <uint8_t *>(salt), SCRYPT_SALT_LEN, N, r, p, hashbuf, sizeof (hashbuf));
1039- if (retval == -1 )
1040- throw std::exception (" libscrypt_scrypt error..." );
1034+ copy (generatedSalt.begin (), generatedSalt.end (), salt);
1035+ salt[generatedSalt.length () - 1 ] = 0 ;
10411036
1042- retval = libscrypt_b64_encode (static_cast <unsigned char *>(hashbuf), sizeof (hashbuf),
1043- outbuf, sizeof (outbuf));
1044- if (retval == -1 )
1045- throw std::exception (" libscrypt_b64_encode error..." );
1037+ auto retval = libscrypt_scrypt (reinterpret_cast <const uint8_t *>(passphrase), strlen (passphrase),
1038+ static_cast <uint8_t *>(salt), SCRYPT_SALT_LEN, N, r, p, hashbuf, sizeof (hashbuf));
10461039
1047- retval = libscrypt_b64_encode (static_cast <unsigned char *>(salt), sizeof (salt),
1048- saltbuf, sizeof (saltbuf));
1040+ if (retval == -1 ) {
1041+ std::cout << " [ " << " libscrypt_scrypt error..." << " ]" ;
1042+ return 0 ;
1043+ }
10491044
1050- if (retval == -1 )
1051- throw std::exception (" libscrypt_b64_encode #2 error..." );
1045+ retval = libscrypt_b64_encode (static_cast <unsigned char *>(hashbuf), sizeof (hashbuf),
1046+ outbuf, sizeof (outbuf));
1047+ if (retval == -1 ) {
1048+ std::cout << " [ " << " libscrypt_b64_encode error..." << " ]" ;
1049+ return 0 ;
1050+ }
10521051
1053- retval = libscrypt_mcf (N, r, p, saltbuf, outbuf, dst);
1054- if (retval != 1 )
1055- throw std::exception (" libscrypt_mcf error..." );
1052+ retval = libscrypt_b64_encode (static_cast <unsigned char *>(salt), sizeof (salt),
1053+ saltbuf, sizeof (saltbuf));
10561054
1057- return 1 ;
1055+ if (retval == -1 ) {
1056+ std::cout << " [ " << " libscrypt_b64_encode #2 error..." << " ]" ;
1057+ return 0 ;
10581058 }
1059- catch (std::exception &e) {
1060- std::cout << " # ERR: HASHINGEXCEPTION in " << __FILE__;
1061- std::cout << " (" << __FUNCTION__ << " ) on line " << __LINE__ << std::endl;
1062- std::cout << " # ERR: " << e.what () << std::endl;
10631059
1060+ retval = libscrypt_mcf (N, r, p, saltbuf, outbuf, dst);
1061+
1062+ if (retval != 1 ) {
1063+ std::cout << " [ " << " libscrypt_mcf error..." << " ]" ;
10641064 return 0 ;
10651065 }
1066+
1067+ return 1 ;
10661068}
10671069
10681070int BlogSystem::change_user_details (std::string user_input, std::string pwd_input, std::shared_ptr<HttpServer::Request> request)
0 commit comments