public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH 2/2] tui: verify email with basic regex
Date: Wed, 21 Jun 2023 14:30:32 +0200	[thread overview]
Message-ID: <20230621123032.744374-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20230621123032.744374-1-d.csapak@proxmox.com>

regex copied from perl gui installer

Signed-off-by: Dominik Csapak <d.csapak@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 (user@domain.tld)")
                 } else {
                     Ok(PasswordOptions {
                         root_password,
-- 
2.30.2





  reply	other threads:[~2023-06-21 12:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-21 12:30 [pve-devel] [PATCH 1/2] tui: always use mail@example.invalid as default email address Dominik Csapak
2023-06-21 12:30 ` Dominik Csapak [this message]
2023-06-21 12:34   ` [pve-devel] [PATCH 2/2] tui: verify email with basic regex Thomas Lamprecht
2023-06-21 12:45   ` Maximiliano Sandoval

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230621123032.744374-2-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal