[Free] Random Password Generator Extension by ChatGPT

I asking for ChatGPT to create Random Password Generator extension for AI2, Mit App Inventor, Kodular type of similar site and the result is insane.

The features

  • Customizable password Length
  • Special character
  • Capital Latter
  • Number

Source code

package com.yourcompany.passwordgenerator;

import android.app.Activity;
import android.content.Context;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.*;
import java.util.Random;

@DesignerComponent(
        version = 1,
        description = "Extension for Customizable Password Generator",
        category = ComponentCategory.EXTENSION,
        nonVisible = true,
        iconName = "https://image.flaticon.com/icons/png/512/632/632351.png")

@SimpleObject(external = true)
//Libraries
@UsesLibraries(libraries = "")
//Permissions
@UsesPermissions(permissionNames = "")

public class PasswordGenerator extends AndroidNonvisibleComponent {

    //Activity and Context
    private Context context;
    private Activity activity;

    public PasswordGenerator(ComponentContainer container){
        super(container.$form());
        this.activity = container.$context();
        this.context = container.$context();
    }

    @SimpleFunction(description = "Generates a random password with customizable options")
    public String GeneratePassword(int passwordLength, int numSpecialChars, int numCapitalLetters, int numNumbers) {

        // Initialize character sets
        String specialChars = "!@#$%^&*()_+-=[]{}|;':\",./<>?";
        String capitalLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String smallLetters = "abcdefghijklmnopqrstuvwxyz";
        String numbers = "0123456789";

        // Create a string builder to construct the password
        StringBuilder password = new StringBuilder();

        // Set up a random generator
        Random random = new Random();

        // Generate the password with the specified criteria
        for (int i = 0; i < passwordLength; i++) {
            // Decide which character set to choose from randomly
            int charSetIndex = random.nextInt(4);

            // Determine which set to use
            String charSet = "";
            switch (charSetIndex) {
                case 0:
                    charSet = specialChars;
                    break;
                case 1:
                    charSet = capitalLetters;
                    break;
                case 2:
                    charSet = smallLetters;
                    break;
                case 3:
                    charSet = numbers;
                    break;
            }

            // Generate a random character from the chosen set
            int charIndex = random.nextInt(charSet.length());
            char randomChar = charSet.charAt(charIndex);

            // Add the character to the password builder
            password.append(randomChar);

            // Count the number of special characters, capital letters, and numbers in the password
            int specialCharCount = 0;
            int capitalLetterCount = 0;
            int numberCount = 0;

            for (int j = 0; j < password.length(); j++) {
                char c = password.charAt(j);
                if (specialChars.indexOf(c) != -1) {
                    specialCharCount++;
                } else if (capitalLetters.indexOf(c) != -1) {
                    capitalLetterCount++;
                } else if (numbers.indexOf(c) != -1) {
                    numberCount++;
                }
            }

            // Check if the criteria for special characters, capital letters, and numbers has been met
            if (specialCharCount == numSpecialChars && capitalLetterCount == numCapitalLetters && numberCount == numNumbers) {
                break;
            }
        }

        // Return the generated password
        return password.toString();
    }
}

Note: I think there was something mistake with the code I hope a expert extension developer spot the mistake and fix it. By the way the extension still usable.

Download the extension
PasswordGenerator.aix (6.4 KB)

6 Likes

How did you compile it?

1 Like

with Nitron IDE

1 Like

without any edit?

1 Like

image

i always got this error…
Whenever i used gpt’s code in nitron ide

1 Like

Yes, First I give a demo project code to ChatGPT for better understanding how it work

1 Like

Can you show me your commands on gpt

1 Like

You need to change the package name according to the ChatGPT package name also you need to edit the file name, I am sorry I am not a extension developer I just create for test and educational propose, For more you need to learn you can contact the extension developer

Thank you

I want to make some basic extension with gpt without knowing java

1 Like

how you do it? Can you explain please?

It’s simple just asking ChatGPT what type of extensions you want don’t forget to mention the extension code must be Java and support for MIT App Inventor, Kodular type similar site.

1 Like

I also made these type of extensions see this video :- https://www.youtube.com/watch?v=hxMcIIqZB6Y

like share and subscribe :heart: :heart:

This was a very good and easy way to generate password! Keep it up!

1 Like

You don’t need to do anything.
Here is an example:

When the button is clicked to generate password, the password in generated and shown in a label.
Nothing more else is needed to do.

1 Like

@Joao_paulo and @Md_Tohaa See the post I just did to know how to do it.