Skip to main content

UserRecord

Struct UserRecord 

Source
pub struct UserRecord {
    pub role: Role,
    pub can_login: bool,
    pub password_declared: bool,
    pub inherit: bool,
    pub superuser: bool,
    /* private fields */
}

Fields§

§role: Role§can_login: bool

v7.39 (read01 round 58) — PG role attributes. CREATE USER is PG’s CREATE ROLE … LOGIN; CREATE ROLE alone cannot log in but can hold privileges and have members. Attributes are NEVER inherited through membership (that is PG’s rule: only privileges flow, not attributes) — a member of a superuser role must SET ROLE to it to act as one.

§password_declared: bool

v7.39 (round 548) — was a password actually DECLARED for this role?

A bare CREATE ROLE devs gets an unguessable credential derived from its own salt (so no record ever carries an empty password), which made “has a hash” useless for telling a real account from a group role. The wire’s open-vs-authenticated decision needs that distinction: it used to arm on ANY role existing, so creating a NOLOGIN group role locked the operator out of their own database — postgres has no password, so nothing could connect afterwards and there was no way back through SQL.

§inherit: bool

INHERIT (the default): this role automatically holds the privileges of every role it is a member of. NOINHERIT means it must SET ROLE to them explicitly.

§superuser: bool

SUPERUSER: bypasses every privilege check.

Implementations§

Source§

impl UserRecord

Source

pub fn verify(&self, password: &str) -> bool

Source

pub fn has_credentials(&self) -> bool

v7.39 (round 548) — can this role be authenticated at all?

A CREATE ROLE devs NOLOGIN records no password and cannot log in. It used to count toward “this server has users, so demand a password from everybody”, which locked the operator out of their own database: postgres has no password, so after creating a group role nothing could connect and there was no way back through SQL.

Source

pub const fn scram(&self) -> Option<&ScramSecrets>

Source

pub const fn mysql_native(&self) -> Option<&[u8; 20]>

v7.17.0 Phase 3.P0-71: borrow the stored mysql_native_password verifier (SHA1(SHA1(password))) for the MySQL-wire shim.

Source

pub const fn caching_sha2(&self) -> Option<&[u8; 32]>

v7.17.0 Phase 3.P0-72: borrow the stored caching_sha2_password verifier (SHA256(SHA256(password))) for the MySQL-wire shim’s fast-path auth.

Source

pub fn verify_caching_sha2_password( &self, scramble: &[u8], client_response: &[u8], ) -> bool

v7.17.0 Phase 3.P0-72 — verify a client caching_sha2_password fast-path response.

Protocol: same XOR shape as mysql_native_password but with SHA-256 instead of SHA-1: client_response = SHA256(password) XOR SHA256(scramble || SHA256(SHA256(password))). Server reconstructs and checks SHA256(reconstructed) == stored_hash.

Full-auth RSA fallback (when the cache misses) is a v7.18 carve-out — clients connecting over plaintext without a cached entry will see Access Denied from the shim until that lands.

Source

pub fn verify_mysql_native_password( &self, scramble: &[u8], client_response: &[u8], ) -> bool

v7.17.0 Phase 3.P0-71 — verify a client mysql_native_password auth response.

Protocol: the client sends a 20-byte response client_proof = SHA1(password) XOR SHA1(scramble || SHA1(SHA1(password))). The server reconstructs SHA1(password) = client_proof XOR SHA1(scramble || stored_hash) and verifies SHA1(reconstructed) == stored_hash. Returns false if the user has no stored hash (loaded from a pre-v7.17 snapshot — the operator has to reset the password to re-populate it).

Trait Implementations§

Source§

impl Clone for UserRecord

Source§

fn clone(&self) -> UserRecord

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UserRecord

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.