Question how to create a array of objects

jabd123

New member
Joined
Dec 5, 2021
Messages
1
Programming Experience
1-3
This is for a user login system which is a small part of a larger project
1. Make the program check the string for uppercase letters, lowercase letters and numbers
2. make it so the username and password are stored together in an array so they can be checked when the user enters the login to check if they match

*codebase is copied at the bottom*


C#:
class account
    {
        protected string username;
        protected string password;
        protected string password1;

        public void createlogin()
        {
            bool valid = false;

            Console.WriteLine("Enter a username ");
            username = Console.ReadLine();


            do
            {
                Console.WriteLine("Enter a password with 8 or more characters that contains at least: \n 1 upper case letter\n 1 lowercase letter\n 1 number");
                password = Console.ReadLine();
                if (password.Length < 8)
                {
                    Console.WriteLine("Your password is less than 8 characters");
                    valid = false;
                }
                else
                {
                    valid = true;
                }
                if (password.Contains("A"))//checks if it contains uppercase letters
                {
                    valid = true;
                }
                else
                {
                    valid = false;
                    Console.WriteLine("Your password didn't contain an Uppercase letter\ntry again");
                }
                if (password.Contains("a"))//checks if it contains lowecase letters
                {
                    valid = true;
                }
                else
                {
                    valid = false;
                    Console.WriteLine("Your password didn't contain a lowercase letter\ntry again");
                }

            } while (valid == false);

            valid = false;
            do
            {
                Console.WriteLine("Re-enter your password");
                password1 = Console.ReadLine();
                if (password != password1)
                {
                    Console.WriteLine("You have entered 2 different password\n please try again");
                    valid = false;
                }
                else
                {
                    valid = true;
                }
            } while (valid == false);


            if (valid == true)
            {

                account[] database = new account[100];     //not sure if this section is correct
                account user1 = new account();

                database[1] = user1;

            }


        }





    }
 

Attachments

  • 1638726242873.png
    1638726242873.png
    51.7 KB · Views: 27
  • 1638726298635.png
    1638726298635.png
    44.7 KB · Views: 25
Last edited by a moderator:
So do you have a specific question or problem? We are not a code writing service, but we can advice you if you ask for specific help.

As an aside, you did the right thing posting the code in code tags. There is no need to post screen shots of the code. In fact, in most programming sites/forums, screen shots of code provides very little value because the other people cannot easily take your code and put it into their IDE to tinker with it an try to help you. You are forcing them to retype your code if you don't provide a more accessible text version.
 
Darn it. And I thought that we had something who could decode this site's toolbar. :D
 

Latest posts

Back
Top Bottom