From: Maximiliano Sandoval <m.sandoval@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
Dominik Csapak <d.csapak@proxmox.com>
Subject: Re: [pve-devel] [PATCH 2/2] tui: verify email with basic regex
Date: Wed, 21 Jun 2023 14:45:34 +0200 (CEST) [thread overview]
Message-ID: <1193072501.600.1687351534134@webmail.proxmox.com> (raw)
In-Reply-To: <20230621123032.744374-2-d.csapak@proxmox.com>
Note that the HTML5 standard [1] suggests
/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
as a regex, I am not sure whats the difference but it might be worth it to check if there is any relevant difference. This is used by the validator crate [2] for example.
[1] https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
[2] https://docs.rs/validator/latest/validator/fn.validate_email.html
> On 21.06.2023 14:30 CEST Dominik Csapak <d.csapak@proxmox.com> wrote:
>
>
> 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
>
>
>
> _______________________________________________
> pve-devel mailing list
> pve-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
prev parent reply other threads:[~2023-06-21 12:45 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 ` [pve-devel] [PATCH 2/2] tui: verify email with basic regex Dominik Csapak
2023-06-21 12:34 ` Thomas Lamprecht
2023-06-21 12:45 ` Maximiliano Sandoval [this message]
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=1193072501.600.1687351534134@webmail.proxmox.com \
--to=m.sandoval@proxmox.com \
--cc=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