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-2014 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 "citrusleaf/cf_types.h"
20 
21 /**
22  * The user name size including null byte.
23  */
24 #define AS_USER_SIZE 64
25 
26 /**
27  * Size of hash buffer including null byte, padded to 8 byte boundary.
28  */
29 #define AS_PASSWORD_HASH_SIZE 64
30 
31 /**
32  * Generate random salt value.
33  * Return true if salt was generated.
34  */
35 bool
36 as_password_gen_salt(char* salt);
37 
38 /**
39  * Create bcrypt hash of password.
40  * Return true if hash was generated.
41  */
42 bool
43 as_password_gen_hash(const char* password, const char* salt, char* hash);
44 
45 /**
46  * Create bcrypt hash of password with constant salt.
47  * Return true if hash was generated.
48  */
49 bool
50 as_password_gen_constant_hash(const char* password, char* hash);
51 
52 /**
53  * If the input password is not hashed, convert to bcrypt hashed password.
54  * Return true if hash was successful.
55  */
56 bool
57 as_password_get_constant_hash(const char* password, char* hash);
58 
59 /**
60  * Prompt for input password from command line if input password is empty.
61  * If the input password is not hashed, convert to bcrypt hashed password.
62  * Return true if hash was successful.
63  */
64 bool
65 as_password_prompt_hash(const char* password, char* hash);
66 
67 /**
68  * Verify password hash. Hash length should always be 60.
69  * Return true if hashes are equal.
70  */
71 static inline bool
72 as_password_verify(const char* hash1, const char* hash2) {
73  return ! memcmp(hash1, hash2, 60);
74 }