MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ACLHashPassword

Function ACLHashPassword

app/redis-6.2.6/src/acl.c:160–175  ·  view source on GitHub ↗

Given an SDS string, returns the SHA256 hex representation as a * new SDS string. */

Source from the content-addressed store, hash-verified

158/* Given an SDS string, returns the SHA256 hex representation as a
159 * new SDS string. */
160sds ACLHashPassword(unsigned char *cleartext, size_t len) {
161 SHA256_CTX ctx;
162 unsigned char hash[SHA256_BLOCK_SIZE];
163 char hex[HASH_PASSWORD_LEN];
164 char *cset = "0123456789abcdef";
165
166 sha256_init(&ctx);
167 sha256_update(&ctx,(unsigned char*)cleartext,len);
168 sha256_final(&ctx,hash);
169
170 for (int j = 0; j < SHA256_BLOCK_SIZE; j++) {
171 hex[j*2] = cset[((hash[j]&0xF0)>>4)];
172 hex[j*2+1] = cset[(hash[j]&0xF)];
173 }
174 return sdsnewlen(hex,HASH_PASSWORD_LEN);
175}
176
177/* Given a hash and the hash length, returns C_OK if it is a valid password
178 * hash, or C_ERR otherwise. */

Callers 2

ACLSetUserFunction · 0.85
ACLCheckUserCredentialsFunction · 0.85

Calls 4

sha256_initFunction · 0.85
sha256_updateFunction · 0.85
sha256_finalFunction · 0.85
sdsnewlenFunction · 0.85

Tested by

no test coverage detected