[pve-devel] [PATCH 2/2] tui: verify email with basic regex

Dominik Csapak d.csapak at proxmox.com
Wed Jun 21 14:30:32 CEST 2023


regex copied from perl gui installer

Signed-off-by: Dominik Csapak <d.csapak at 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 at example.invalid" {
                     Err("invalid email address")
+                } else if !email_regex.is_match(&email) {
+                    Err("Email does not look like a valid address (user at domain.tld)")
                 } else {
                     Ok(PasswordOptions {
                         root_password,
-- 
2.30.2






More information about the pve-devel mailing list