2
0

crypt.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*-------------------------------------------------------------------------
  2. *
  3. * crypt.h
  4. * Interface to libpq/crypt.c
  5. *
  6. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  7. * Portions Copyright (c) 1994, Regents of the University of California
  8. *
  9. * src/include/libpq/crypt.h
  10. *
  11. *-------------------------------------------------------------------------
  12. */
  13. #ifndef PG_CRYPT_H
  14. #define PG_CRYPT_H
  15. #include "datatype/timestamp.h"
  16. /*
  17. * Types of password hashes or secrets.
  18. *
  19. * Plaintext passwords can be passed in by the user, in a CREATE/ALTER USER
  20. * command. They will be encrypted to MD5 or SCRAM-SHA-256 format, before
  21. * storing on-disk, so only MD5 and SCRAM-SHA-256 passwords should appear
  22. * in pg_authid.rolpassword. They are also the allowed values for the
  23. * password_encryption GUC.
  24. */
  25. typedef enum PasswordType
  26. {
  27. PASSWORD_TYPE_PLAINTEXT = 0,
  28. PASSWORD_TYPE_MD5,
  29. PASSWORD_TYPE_SCRAM_SHA_256
  30. } PasswordType;
  31. extern PasswordType get_password_type(const char *shadow_pass);
  32. extern char *encrypt_password(PasswordType target_type, const char *role,
  33. const char *password);
  34. extern char *get_role_password(const char *role, const char **logdetail);
  35. extern int md5_crypt_verify(const char *role, const char *shadow_pass,
  36. const char *client_pass, const char *md5_salt,
  37. int md5_salt_len, const char **logdetail);
  38. extern int plain_crypt_verify(const char *role, const char *shadow_pass,
  39. const char *client_pass,
  40. const char **logdetail);
  41. #endif