IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

fenetre d'authentification winform


Sujet :

C#

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    193
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2010
    Messages : 193
    Par défaut fenetre d'authentification winform
    Bonjour,

    j'ai un form1 avec un bouton parametre qui ouvre un form2, fenetre d'authentification.

    A ce form2, j'ai codé des regex. Lorsqu'un champ est mal renseigné, celui-ci m'affiche bien
    une boîte de dialogue qui mentionne : "ce champ est incorrect" OK ?

    Lorsque je clique sur le bouton "OK" du message d'erreur, par la suite ma fenetre
    d'authentification s'en va.

    Je souhaiterais savoir donc comment faire pour que ma fenetre d'authentification reste sous mes yeux
    après le clique sur le bouton "OK" du message d'erreur.

    merci de vos réponses

    cordialement

  2. #2
    Modérateur
    Avatar de toopac
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2009
    Messages
    940
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2009
    Messages : 940
    Par défaut
    Salut ismababa,

    comment et quand affiches-tu le message "ce champ est incorrect"?

    Tu peux nous montrer le bout de ton code correspondant?

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    193
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2010
    Messages : 193
    Par défaut
    salut toopac

    oui voici le code, j'ai tout mis au cas où ça proviendrait d'une erreur de codage.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
     public partial class Form2 : Form
        {
            MD5CryptoServiceProvider check = new MD5CryptoServiceProvider();
     
     
            public Form2()
            {
                InitializeComponent();
            }
     
            private void Form2_Load(object sender, EventArgs e)
            {
                this.txtBoxUserName.Validating += new 
                    System.ComponentModel.CancelEventHandler(this.txtBoxUserName_Validating);
     
                this.txtBoxMDP.Validating += new 
                    System.ComponentModel.CancelEventHandler(this.txtBoxMDP_Validating);
     
                this.txtBoxURL.Validating += new 
                    System.ComponentModel.CancelEventHandler(this.txtBoxURL_Validating);
            }
     
            private void button2_Click(object sender, EventArgs e) // bouton valider
            {
     
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
     
                if (!UrlValide(txtBoxURL.Text))
                    MessageBox.Show("Format Url invalide !");
     
     
                else if (txtBoxMDP.Text == "")
                    MessageBox.Show("Veuillez saisir le mot de passe.");
     
     
                else if (txtBoxUserName.Text == "")
                    MessageBox.Show("Veuillez saisir le nom d'utilisateur.");
     
     
                else if ((txtBoxMDP.Text == "") && (txtBoxURL.Text == "") && (txtBoxUserName.Text == ""))
                    MessageBox.Show("aucun champ n'a été renseigner !!!" + "\n" + "Recommencer");
     
     
                else
                {
                    string valide = "";
                    valide += "Nom Utilisateur : " + txtBoxUserName.Text + "\n" + "Mot de Passe : " + toMD5(txtBoxMDP.Text) +
                        "\n" + " URL : " + txtBoxURL.Text;
                    MessageBox.Show(valide, "validation effectué");
                }
     
     
     
                if (txtBoxUserName.Text != "" && txtBoxMDP.Text != "" && txtBoxURL.Text != "")
                {
                    string valide = "";
                    valide += "Nom Utilisateur : " + txtBoxUserName.Text + "\n" + "Mot de Passe : " + toMD5(txtBoxMDP.Text) +
                        "\n" + " URL : " + txtBoxURL.Text;
     
                }
     
                DialogResult = DialogResult.Cancel;
                Close();
            }
     
     
            private bool UrlValide(string UrlVal)
            {
                bool UrlV;
                UrlV = Regex.IsMatch(UrlVal, @"^(http://|https://){0,1}[A-Za-z0-9][A-Za-z0-9\-\.]+[A-Za-z0-9]\.[A-Za-z]{2,}[\43-\176]*$");
                return UrlV;
            }
     
            private void button1_Click(object sender, EventArgs e) // bouton effacer
            {
                txtBoxMDP.Clear();
                txtBoxUserName.Clear();
                txtBoxURL.Clear();
                txtBoxUserName.Focus();
            }
     
     
            private void txtBoxUserName_Validating(object sender, System.ComponentModel.CancelEventArgs e)
            {
                if (txtBoxUserName.TextLength == 0)
                {
                    errorProvider1.SetError(txtBoxUserName, "Mettre votre pseudo");
                    e.Cancel = true;
                }
                else
                {
                    errorProvider1.SetError(txtBoxUserName, null);
                }
                button1.CausesValidation = false;
            }
     
     
            private void txtBoxMDP_Validating(object sender, System.ComponentModel.CancelEventArgs e)
            {
                if (txtBoxMDP.TextLength == 0)
                {
                    errorProvider1.SetError(txtBoxMDP, "Mettre un mot de passe");
                    e.Cancel = true;
                }
                else
                {
                    errorProvider1.SetError(txtBoxMDP, null);
                }
                button1.CausesValidation = false;
            }
     
            private void txtBoxURL_Validating(object sender, System.ComponentModel.CancelEventArgs e)
            {
                if (txtBoxURL.TextLength == 0)
                {
                    errorProvider1.SetError(txtBoxURL, "Mettre l'URL");
                    e.Cancel = true;
                }
                else
                {
                    errorProvider1.SetError(txtBoxURL, null);
                }
                button1.CausesValidation = false;
            }

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    193
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2010
    Messages : 193
    Par défaut
    Re^^

    Non ça ne me le reconnait pas

  5. #5
    Membre confirmé Avatar de Klivor
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    143
    Détails du profil
    Informations personnelles :
    Âge : 33
    Localisation : France

    Informations forums :
    Inscription : Janvier 2011
    Messages : 143
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     private void button2_Click(object sender, EventArgs e) // bouton valider
            {
     
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
    A quoi te sert le this.close ?

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    193
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2010
    Messages : 193
    Par défaut
    Oups nan ça vient pas de ça n'y fait pas attention

    ça c'est pour le bouton de fermeture

    Meme quand je l'enlève le résultat est le meme

  7. #7
    Membre confirmé
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    193
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2010
    Messages : 193
    Par défaut
    ok mais j'ai 4 erreurs toopac

    3 comme ça

    et une ci-dessous :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    if (errorMessage.IsNullOrEmpty)

  8. #8
    Modérateur
    Avatar de toopac
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2009
    Messages
    940
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2009
    Messages : 940
    Par défaut
    ben tu fermes ton formulaire quand tu cliques sur le bouton de validation quoi qu'il arrive.


    Je suis pas sûr d'avoir bien tout compris ton code, mais j'aurai fais plus un truc du genre :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    private void button2_Click(object sender, EventArgs e) // bouton valider
            {
                string errorMessage = "";
                if ((txtBoxMDP.Text == "") && (txtBoxURL.Text == "") && (txtBoxUserName.Text == ""))
                    errorMessage ="aucun champ n'a été renseigné !!!" + "\n" + "Recommencer");
                else
                {
                    if (!UrlValide(txtBoxURL.Text))
                        errorMessage += "Format Url invalide !" + Environement.NewLine;
                    if (txtBoxMDP.Text == "")
                        errorMessage += "Veuillez saisir le mot de passe." + Environement.NewLine;
                    if (txtBoxUserName.Text == "")
                        errorMessage += "Veuillez saisir le nom d'utilisateur."+ Environement.NewLine;
                }
     
                if (errorMessage.IsNullOrEmpty)
                {
                    MessageBox.Show(errorMessage);
                }
     
                else
                {
                    string valide = "";
                    valide += "Nom Utilisateur : " + txtBoxUserName.Text + "\n" + "Mot de Passe : " + toMD5(txtBoxMDP.Text) +
                        "\n" + " URL : " + txtBoxURL.Text;
                    MessageBox.Show(valide, "validation effectué");
                    this.Close();
                }
            }

  9. #9
    Membre confirmé Avatar de Klivor
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    143
    Détails du profil
    Informations personnelles :
    Âge : 33
    Localisation : France

    Informations forums :
    Inscription : Janvier 2011
    Messages : 143
    Par défaut
    Citation Envoyé par toopac Voir le message
    ben tu fermes ton formulaire quand tu cliques sur le bouton de validation quoi qu'il arrive.


    Je suis pas sûr d'avoir bien tout compris ton code, mais j'aurai fais plus un truc du genre :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    private void button2_Click(object sender, EventArgs e) // bouton valider
            {
                string errorMessage = "";
                if ((txtBoxMDP.Text == "") && (txtBoxURL.Text == "") && (txtBoxUserName.Text == ""))
                    errorMessage ="aucun champ n'a été renseigné !!!" + "\n" + "Recommencer");
                else
                {
                    if (!UrlValide(txtBoxURL.Text))
                        errorMessage += "Format Url invalide !" + Environement.NewLine;
                    if (txtBoxMDP.Text == "")
                        errorMessage += "Veuillez saisir le mot de passe." + Environement.NewLine;
                    if (txtBoxUserName.Text == "")
                        errorMessage += "Veuillez saisir le nom d'utilisateur."+ Environement.NewLine;
                }
     
                if (errorMessage.IsNullOrEmpty)
                {
                    MessageBox.Show(errorMessage);
                }
     
                else
                {
                    string valide = "";
                    valide += "Nom Utilisateur : " + txtBoxUserName.Text + "\n" + "Mot de Passe : " + toMD5(txtBoxMDP.Text) +
                        "\n" + " URL : " + txtBoxURL.Text;
                    MessageBox.Show(valide, "validation effectué");
                    this.Close();
                }
            }
    On est d'accord 2pac

  10. #10
    Membre confirmé Avatar de Klivor
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    143
    Détails du profil
    Informations personnelles :
    Âge : 33
    Localisation : France

    Informations forums :
    Inscription : Janvier 2011
    Messages : 143
    Par défaut
    Re ^^ ,
    essaye de faire: NomForm.show()

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. fenetre d'authentification avec SWING
    Par riadhhwajdii dans le forum AWT/Swing
    Réponses: 3
    Dernier message: 23/08/2010, 14h45
  2. [Sécurité] Fenêtre d'authentification en php
    Par The Wretched dans le forum Langage
    Réponses: 7
    Dernier message: 05/08/2008, 16h26
  3. Protéger l'application avec fenetre d'authentification
    Par abbd dans le forum Windows Forms
    Réponses: 2
    Dernier message: 18/05/2008, 18h34
  4. Fenetre d'authentification inexistante
    Par Chronax dans le forum Windows XP
    Réponses: 2
    Dernier message: 29/02/2008, 16h10
  5. ogre et fenetre de dialogue Winform = crash
    Par zmatz dans le forum Ogre
    Réponses: 1
    Dernier message: 05/08/2007, 02h33

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo