Visualizzazione dei risultati da 1 a 4 su 4

Discussione: password casuale

  1. #1

    password casuale

    Sto usando questo codice per generare una pwd casuale con .NET/VB ma ricevo un errore

    Codice PHP:
    Dim Num As New Random(100
    Dim LCases As New Random(500)
    Dim UCases As New Random(50)
    Dim Psw As String ""
    Dim SelezioneRandom As New Random(50)
    Dim i As Integer
    Dim Cnt
    (2) As Integer
    Dim CharSel
    (2) As Integer
    Dim ISel 
    As Integer
    Dim lunghezza 
    As Integer 7

    For 1 To Lunghezza

    Cnt
    (0) = Num.Next(4857)
    Cnt(1) = LCases.Next(6590)
    Cnt(2) = UCases.Next(97122)

    CharSel(0) = System.Convert.ToChar(Cnt(0)).ToString
    CharSel
    (1) = System.Convert.ToChar(Cnt(1)).ToString
    CharSel
    (2) = System.Convert.ToChar(Cnt(2)).ToString

    ISel 
    SelezioneRandom.Next(03)
    Psw &= CharSel(ISel)

    Next 
    L'errore è qui

    codice:
    CharSel(1) = System.Convert.ToChar(Cnt(1)).ToString
    
    System.FormatException: Input string was not in a correct format. 
    
    StackTrace:
    [InvalidCastException: Conversion from string "X" to type 'Integer' is not valid.]
    Siccome non sono praticissima di .NET e mi sto sforzando molto :master: non è che mi dareste un piccolo suggerimento?
    Sto ancora imparando.... Chiedo comprensione!
    !...Send ME a message...!

  2. #2
    l'errore sta nel fatto che tu fai un cast a char con: System.Conver.ToChar e poi lo assegni ad una varibile con tipo integer.

    Cambia il tipo di CharSel da Integer a Char

    Ciao

  3. #3
    Utente di HTML.it L'avatar di albgen
    Registrato dal
    Jun 2005
    Messaggi
    3,249
    ecco come si generano password veramente casuali

    C#

    public static string RandomPassword(int length)
    {
    StringBuilder temp = new StringBuilder(32);
    for (int i = 0; i <= (length/32); i++)
    temp.Append(Guid.NewGuid().ToString("N"));
    return temp.ToString().Substring(0, length);
    }


    VB.NET

    # Public Shared Function RandomPassword(ByVal length As Integer) As String
    # Dim temp As New StringBuilder(32)
    # For i As Integer = 0 To (length / 32)
    # temp.Append(Guid.NewGuid().ToString("N"))
    # Next
    # Return temp.ToString().Substring(0, length)
    # End Function
    I got the remedy

  4. #4
    Grazie mille!
    Alla fine, merito della mia mente ECCELSA :ignore: ho risolto adottando una combinazione delle due soluzioni.
    Come al solito, se ho imparato qualche altra cosina, lo devo a voi!!

    Sto ancora imparando.... Chiedo comprensione!
    !...Send ME a message...!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.