You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
GameAtlas/GameAtlas/GameAtlas/Views/PageInscription.xaml.cs

89 lines
2.6 KiB

namespace GameAtlas.Views;
using GameAtlas.Models;
using GameAtlas.DataContractPersistance;
using System.Diagnostics;
using System.Text.RegularExpressions;
public partial class PageInscription : ContentPage
{
DataContractPers PersistanceManager = new DataContractPers();
public Manager InscriptionManager => (App.Current as App).MyManager;
public PageInscription()
{
InitializeComponent();
}
private async void OnSignUpClicked(object sender, EventArgs e)
{
string mail = email.Text;
string username = pseudo.Text;
string password = mdp.Text;
if(string.IsNullOrWhiteSpace(mail) || string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
{
await DisplayAlert("Erreur", "Entrez tous les champs", "Ok");
return;
}
else if (!Regex.IsMatch(mail, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
{
await DisplayAlert("Erreur","Email non valide","Ok");
return;
}
if (IsPasswordStrong(password) == false)
{
await DisplayAlert("Erreur", "Le mot de passe n'est pas assez fort", "OK");
return;
}
Utilisateur utilisateur = new Utilisateur(mail, username, password);
InscriptionManager.AddUtilisateur(utilisateur);
InscriptionManager.SauvegardeDonnees();
//PersistanceManager.SauvegardeUser(utilisateur);
Debug.WriteLine(InscriptionManager.Utilisateurs.Count);
//await Navigation.PushAsync(new PageAcceuil());
await Shell.Current.GoToAsync("//page/PageAccueil");
bool IsPasswordStrong(string password)
{
// Vérifier si le mot de passe est assez long
if (password.Length < 8)
{
return false;
}
// Vérifier si le mot de passe contient au moins une majuscule, une minuscule et un chiffre
bool hasUppercase = false;
bool hasLowercase = false;
bool hasDigit = false;
foreach (char c in password)
{
if (char.IsUpper(c))
{
hasUppercase = true;
}
else if (char.IsLower(c))
{
hasLowercase = true;
}
else if (char.IsDigit(c))
{
hasDigit = true;
}
}
return hasUppercase && hasLowercase && hasDigit;
}
}
}