Skip to content

Commit

Permalink
percent encoding of passwords
Browse files Browse the repository at this point in the history
Signed-off-by: SHIMIZU Toshihiro <[email protected]>
  • Loading branch information
toshirin33 committed Mar 18, 2021
1 parent 8c669cf commit 38ee726
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions experimental/plugins/postgres_storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ log-panics = "2.0.0"
postgres = "0.15.2"
r2d2 = "0.8.2"
r2d2_postgres = "0.14.0"
percent-encoding = "2.1.0"

[dependencies.uuid]
version = "0.5.0"
Expand Down
8 changes: 6 additions & 2 deletions experimental/plugins/postgres_storage/src/postgres_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ extern crate owning_ref;
extern crate sodiumoxide;
extern crate r2d2;
extern crate r2d2_postgres;
extern crate percent_encoding;

use ::std::sync::RwLock;

Expand All @@ -13,6 +14,8 @@ use self::owning_ref::OwningHandle;
use std::rc::Rc;
use std::time::Duration;

use self::percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};

use errors::wallet::WalletStorageError;
use errors::common::CommonError;
use wql::language;
Expand Down Expand Up @@ -1037,19 +1040,20 @@ impl PostgresStorageType {
}
url_base.push_str(":");
match credentials.admin_password {
Some(ref password) => url_base.push_str(&password[..]),
Some(ref password) => url_base.push_str(&utf8_percent_encode(&password[..], &NON_ALPHANUMERIC).to_string()),
None => ()
}
url_base.push_str("@");
url_base.push_str(&config.url[..]);
url_base.push_str("/postgres");
url_base
}

fn _base_postgres_url(config: &PostgresConfig, credentials: &PostgresCredentials) -> String {
let mut url_base = "postgresql://".to_owned();
url_base.push_str(&credentials.account[..]);
url_base.push_str(":");
url_base.push_str(&credentials.password[..]);
url_base.push_str(&utf8_percent_encode(&credentials.password[..], &NON_ALPHANUMERIC).to_string());
url_base.push_str("@");
url_base.push_str(&config.url[..]);
url_base
Expand Down

0 comments on commit 38ee726

Please sign in to comment.