All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
as_password.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2018 Aerospike, Inc.
3  *
4  * Portions may be licensed to Aerospike, Inc. under one or more contributor
5  * license agreements.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
8  * use this file except in compliance with the License. You may obtain a copy of
9  * the License at http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14  * License for the specific language governing permissions and limitations under
15  * the License.
16  */
17 #pragma once
18 
19 #include <aerospike/as_std.h>
20 #include <string.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /**
27  * The user name size including null byte.
28  */
29 #define AS_USER_SIZE 64
30 
31 /**
32  * Size of hash buffer including null byte, padded to 8 byte boundary.
33  */
34 #define AS_PASSWORD_HASH_SIZE 64
35 
36 /**
37  * Generate random salt value.
38  * Return true if salt was generated.
39  */
40 bool
41 as_password_gen_salt(char* salt);
42 
43 /**
44  * Create bcrypt hash of password.
45  * Return true if hash was generated.
46  */
47 bool
48 as_password_gen_hash(const char* password, const char* salt, char* hash);
49 
50 /**
51  * Create bcrypt hash of password with constant salt.
52  * Return true if hash was generated.
53  */
54 bool
55 as_password_gen_constant_hash(const char* password, char* hash);
56 
57 /**
58  * If the input password is not hashed, convert to bcrypt hashed password.
59  * Return true if hash was successful.
60  */
61 bool
62 as_password_get_constant_hash(const char* password, char* hash);
63 
64 /**
65  * Prompt for input password from command line if input password is empty.
66  * If the input password is not hashed, convert to bcrypt hashed password.
67  * Return true if hash was successful.
68  */
69 AS_EXTERN bool
70 as_password_prompt_hash(const char* password, char* hash);
71 
72 AS_EXTERN void
73 as_password_acquire(char* password_trg, const char* password_src, int size);
74 
75 /**
76  * Verify password hash. Hash length should always be 60.
77  * Return true if hashes are equal.
78  */
79 static inline bool
80 as_password_verify(const char* hash1, const char* hash2) {
81  return ! memcmp(hash1, hash2, 60);
82 }
83 
84 #ifdef __cplusplus
85 } // end extern "C"
86 #endif
AS_EXTERN void as_password_acquire(char *password_trg, const char *password_src, int size)
bool as_password_gen_hash(const char *password, const char *salt, char *hash)
bool as_password_gen_salt(char *salt)
bool as_password_gen_constant_hash(const char *password, char *hash)
#define AS_EXTERN
Definition: as_std.h:25
AS_EXTERN bool as_password_prompt_hash(const char *password, char *hash)
static bool as_password_verify(const char *hash1, const char *hash2)
Definition: as_password.h:80
bool as_password_get_constant_hash(const char *password, char *hash)