BCryptTest.C 900 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * Copyright (C) 2011 Emweb bvba, Kessel-Lo, Belgium.
  3. *
  4. * See the LICENSE file for terms of use.
  5. */
  6. #include <boost/date_time/posix_time/posix_time.hpp>
  7. #include <boost/test/unit_test.hpp>
  8. #include <Wt/WRandom>
  9. #include <Wt/Auth/HashFunction>
  10. using namespace Wt;
  11. BOOST_AUTO_TEST_CASE( bcrypt_test )
  12. {
  13. Auth::BCryptHashFunction f(7);
  14. std::string msg = "secret";
  15. std::string salt = WRandom::generateId();
  16. std::string hash = f.compute(msg, salt);
  17. std::cerr << "bcrypted password: " << hash << std::endl;
  18. boost::posix_time::ptime
  19. start = boost::posix_time::microsec_clock::local_time();
  20. BOOST_REQUIRE(f.verify(msg, salt, hash));
  21. boost::posix_time::ptime
  22. end = boost::posix_time::microsec_clock::local_time();
  23. boost::posix_time::time_duration d = end - start;
  24. std::cerr << "verify() took: " << (double)d.total_microseconds() / 1000
  25. << "ms" << std::endl;
  26. }