aboutsummaryrefslogtreecommitdiffstats
path: root/doc/examples/bcrypt.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2011-04-08 14:57:49 +0000
committerlloyd <[email protected]>2011-04-08 14:57:49 +0000
commitfc62f7f284387a180e42402e8706965a666efba7 (patch)
tree9abe74c670993c111bd3a5bf5fb568767f9e75be /doc/examples/bcrypt.cpp
parent438f3eb73e494fcab82b239452d712bec06f48c9 (diff)
More pubkey doc updates
Diffstat (limited to 'doc/examples/bcrypt.cpp')
-rw-r--r--doc/examples/bcrypt.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/doc/examples/bcrypt.cpp b/doc/examples/bcrypt.cpp
new file mode 100644
index 000000000..27a98cf33
--- /dev/null
+++ b/doc/examples/bcrypt.cpp
@@ -0,0 +1,45 @@
+/*
+* Bcrypt example
+* (C) 2011 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#include <botan/botan.h>
+#include <botan/bcrypt.h>
+#include <iostream>
+
+using namespace Botan;
+
+int main(int argc, char* argv[])
+ {
+ if(argc != 2 && argc != 3)
+ {
+ std::cout << "Usage: " << argv[0] << " password\n"
+ << " " << argv[0] << " password passhash\n";
+ return 1;
+ }
+
+ LibraryInitializer init;
+
+ if(argc == 2)
+ {
+ AutoSeeded_RNG rng;
+
+ std::cout << generate_bcrypt(argv[1], rng, 12) << "\n";
+ }
+ else if(argc == 3)
+ {
+ if(strlen(argv[2]) != 60)
+ {
+ std::cout << "Note: hash " << argv[2]
+ << " has wrong length and cannot be valid\n";
+ }
+
+ const bool ok = check_bcrypt(argv[1], argv[2]);
+
+ std::cout << "Password is " << (ok ? "valid" : "NOT valid") << "\n";
+ }
+
+ return 0;
+ }