File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ impl PgConnection {
7777
7878 stream
7979 . send ( Password :: Cleartext (
80- options. password . as_deref ( ) . unwrap_or_default ( ) ,
80+ & options. get_password ( ) . unwrap_or_default ( ) ,
8181 ) )
8282 . await ?;
8383 }
@@ -91,7 +91,7 @@ impl PgConnection {
9191 stream
9292 . send ( Password :: Md5 {
9393 username : & options. username ,
94- password : options. password . as_deref ( ) . unwrap_or_default ( ) ,
94+ password : & options. get_password ( ) . unwrap_or_default ( ) ,
9595 salt : body. salt ,
9696 } )
9797 . await ?;
Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ pub(crate) async fn authenticate(
8787
8888 // SaltedPassword := Hi(Normalize(password), salt, i)
8989 let salted_password = hi (
90- options. password . as_deref ( ) . unwrap_or_default ( ) ,
90+ & options. get_password ( ) . unwrap_or_default ( ) ,
9191 & cont. salt ,
9292 cont. iterations ,
9393 ) ?;
Original file line number Diff line number Diff line change @@ -519,6 +519,21 @@ impl PgConnectOptions {
519519 & self . username
520520 }
521521
522+ /// Get the password.
523+ ///
524+ /// ```rust
525+ /// # use sqlx_postgres::PgConnectOptions;
526+ /// let options = PgConnectOptions::new()
527+ /// .password("53C237");
528+ /// assert_eq!(options.get_password().as_deref(), Some("53C237"));
529+ /// ```
530+ pub fn get_password ( & self ) -> Option < Cow < ' _ , str > > {
531+ if self . password . is_some ( ) {
532+ return self . password . as_deref ( ) . map ( Cow :: Borrowed ) ;
533+ }
534+ None
535+ }
536+
522537 /// Get the current database name.
523538 ///
524539 /// # Example
You can’t perform that action at this time.
0 commit comments