regex copied from perl gui installer Signed-off-by: Dominik Csapak <d.csa...@proxmox.com> --- this needs librust-regex-dev as build-dependency proxmox-tui-installer/Cargo.toml | 1 + proxmox-tui-installer/src/main.rs | 8 ++++++++ 2 files changed, 9 insertions(+)
diff --git a/proxmox-tui-installer/Cargo.toml b/proxmox-tui-installer/Cargo.toml index 9d57b5b..5a50c69 100644 --- a/proxmox-tui-installer/Cargo.toml +++ b/proxmox-tui-installer/Cargo.toml @@ -11,5 +11,6 @@ homepage = "https://www.proxmox.com" cursive = { version = "0.20.0", default-features = false, features = ["termion-backend"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" +regex = "1.7" proxmox-sys = "0.5.0" diff --git a/proxmox-tui-installer/src/main.rs b/proxmox-tui-installer/src/main.rs index 77cfb63..2d048f0 100644 --- a/proxmox-tui-installer/src/main.rs +++ b/proxmox-tui-installer/src/main.rs @@ -25,6 +25,8 @@ use cursive::{ Cursive, CursiveRunnable, ScreenId, View, XY, }; +use regex::Regex; + use proxmox_sys::linux::procfs; mod options; @@ -484,12 +486,18 @@ fn password_dialog(siv: &mut Cursive) -> InstallerView { .get_value::<EditView, _>(2) .ok_or("failed to retrieve email")?; + let email_regex = + Regex::new(r"^[\w\+\-\~]+(\.[\w\+\-\~]+)*@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*$") + .unwrap(); + if root_password.len() < 5 { Err("password too short") } else if root_password != confirm_password { Err("passwords do not match") } else if email == "mail@example.invalid" { Err("invalid email address") + } else if !email_regex.is_match(&email) { + Err("Email does not look like a valid address (u...@domain.tld)") } else { Ok(PasswordOptions { root_password, -- 2.30.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel