I'm making a little utility to help me remember passwords by repetition. I'd like to enter password to be remembered only once every day and not before each session. Of course, I wouldn't store a password itself, but would gladly store its hash.
So, what are the easiest ways to get a hash from std::string
using the C++ Standard Library?
For a quick solution involving no external libraries, you can use
hash<std::string>
to hashstring
s. It's defined by including the header fileshash_map
orunordered_map
(or some others too).If you decide you want the added security of SHA, you don't have to download the large Crypto++ library if you don't need all its other features; there are plenty of standalone implementations on the internet, just search for "sha implementation c++".
using c++11, you can:
see more here.
You can use the STL functor hash. See if your STL lib has it or not.
Note that this one returns a
size_t
, so range isnumeric_limits<size_t>::min()
numeric_limits<size_t>::max()
. You'll have to use SHA or something if that's not acceptable..