aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/examples/bcrypt.cpp32
-rw-r--r--src/examples/examples.h9
-rw-r--r--src/main.cpp8
3 files changed, 48 insertions, 1 deletions
diff --git a/src/examples/bcrypt.cpp b/src/examples/bcrypt.cpp
new file mode 100644
index 000000000..50205cd4d
--- /dev/null
+++ b/src/examples/bcrypt.cpp
@@ -0,0 +1,32 @@
+#include "examples.h"
+#include <botan/bcrypt.h>
+
+int bcrypt_example(int argc, char* argv[])
+ {
+ if(argc == 2)
+ {
+ AutoSeeded_RNG rng;
+
+ const std::string password = argv[1];
+
+ std::cout << generate_bcrypt(password, rng, 12) << "\n";
+ return 0;
+ }
+ else if(argc == 3)
+ {
+ const std::string password = argv[1];
+ const std::string hash = argv[2];
+
+ if(hash.length() != 60)
+ std::cout << "Note: bcrypt '" << hash << "' has wrong length and cannot be valid\n";
+
+ const bool ok = check_bcrypt(password, hash);
+
+ std::cout << "Password is " << (ok ? "valid" : "NOT valid") << "\n";
+ return (ok ? 0 : 1);
+ }
+
+ std::cout << "Usage: " << argv[0] << " password\n"
+ << " " << argv[0] << " password passhash\n";
+ return 1;
+ }
diff --git a/src/examples/examples.h b/src/examples/examples.h
new file mode 100644
index 000000000..0fdc27121
--- /dev/null
+++ b/src/examples/examples.h
@@ -0,0 +1,9 @@
+
+#include "../common.h"
+#include <botan/auto_rng.h>
+#include <botan/hex.h>
+#include <iostream>
+
+using namespace Botan;
+
+int bcrypt_example(int argc, char* argv[]);
diff --git a/src/main.cpp b/src/main.cpp
index 05b0eed85..7446eef62 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -27,6 +27,7 @@ using namespace Botan;
#include "common.h"
#include "speed/speed.h"
#include "tests/tests.h"
+#include "examples/examples.h"
// from common.h
void strip_comments(std::string& line)
@@ -99,7 +100,7 @@ int main(int argc, char* argv[])
if(opts.is_set("help") || argc < 2)
{
- std::cout << "Commands: test version time\n";
+ std::cout << "Commands: test version time bcrypt\n";
return 1;
}
@@ -117,6 +118,11 @@ int main(int argc, char* argv[])
return failures ? 1 : 0;
}
+ if(cmd == "bcrypt")
+ {
+ bcrypt_example(argc - 1, argv + 1);
+ }
+
if(cmd == "speed")
{
double seconds = 5;