B4J Library [B4X] B4XPassword b4xlib (B4A, B4i, B4J)

B4XPassword Library v1.3
Hi, I wanted to share this library that I made.
EDIT: I have updated it to v1.2 which corrects the ASCII table values. rnd uses one value higher for the second value.
v1.3 now generates a password between interval min and max. so 1 means 1 char and 10 means 10. ThRuST Logic :)

Example: If Randy = 1 Then RandChar1 = Rnd(49, 58) since ASCII 57 = 9
Enough science!! Download and play :)

Usage: (pass min and max lenght)
Usage:
' Use it like this
    Dim MyPassword As String
    MyPassword = B4XPassword.Randomize_Password(3, 10)

Hopefully someone finds it useful.

Here's is B4XPasswords v1.3 code module
B4XPassword:
' B4XPassword Generator Library by ThRuST
' v1.2     2022-06-30    Corrected the ASCII table chars.
' v1.3     2022-06-31     The generator now uses a min and max value for varied lenght.
' Random lenght should work between the intervals now.

' Reference: https://hscboards.fandom.com/wiki/ASCII_Codes

' Shared with the B4X community.
' Play around with the GUI min and max to find the parameter you prefer.
' Have fun :-)

Sub Process_Globals
    Private fx As JFX
 
    Private Randy As Int
    Private RandChar1, RandChar2 , RandChar3, RandChar4, RandChar5 As Int
    Private PassStr(5000) As String
    Private MyPass As String
 
End Sub

' Randomize a password with min and max parameter.
' A randomized password between the min and max range will be generated.
' Example usage: string = B4XPassword.Randomize_Password(3,10)
' This will randomize a password with lenght between 3 and 10
Public Sub Randomize_Password(PassMin As Int, PassMax As Int)
 
    ' Reset result string
    MyPass = ""
    ' Randomize ASCII int
    Dim Randy As Int
    Dim PassLgt As Int = Rnd(PassMin, PassMax + 1)
 
    ' Loop begins
    For i = 1 To PassLgt
 
        Randy = Rnd(1, 6)
 
        If Randy = 1 Then RandChar1 = Rnd(49, 58)
        If Randy = 2 Then RandChar2 = Rnd(69, 91)
        If Randy = 3 Then RandChar3 = Rnd(97, 123)
        If Randy = 4 Then RandChar4 = 45 ' -
        If Randy = 5 Then RandChar5 = 33 ' !
 
        If Randy = 1 Then PassStr(i) = Chr(RandChar1)
        If Randy = 2 Then PassStr(i) = Chr(RandChar2)
        If Randy = 3 Then PassStr(i) = Chr(RandChar3)
        If Randy = 4 Then PassStr(i) = Chr(RandChar4)
        If Randy = 5 Then PassStr(i) = Chr(RandChar5)
 
        ' Store char array in string
        MyPass = MyPass & PassStr(i)
 
    Next
 
    ' Pass it back
    Return MyPass
 
End Sub

Note about this files:
v1.3 is now available as device specific libraries for B4A and B4J. (B4A version also works with B4i but shows as v1.0) :)?
EDIT: The b4xlib version is uploaded anew since it works. The last file is the b4xlib so that's all you need for all platforms.

Credits to @stevel05 for the solution to how to make a b4xlib.

/ThRuST
 

Attachments

  • B4XPassword Library v1.3.zip
    391.1 KB · Views: 199
  • B4XPassword v1.3 B4J.zip
    2.6 KB · Views: 210
  • B4XPassword v1.3 B4A.zip
    2.3 KB · Views: 185
  • B4XPassword v1.3.b4xlib
    1.3 KB · Views: 200
Last edited:

ThRuST

Well-Known Member
Licensed User
Longtime User
Thanks, as many users entered this thread I should say that I changed the code to only use one parameter (max lenght).
so if anyone downloaded the first which used two just download it again and trash the first v1.0 !! Things move quickly in reality.
(And dreams move slower) :) Enjoy
Roger
 

ThRuST

Well-Known Member
Licensed User
Longtime User
Oh, and you might need this!! I left the zero out because I don't like that it gets confusing with oO and 0

See the ASCII table here
 

josejad

Expert
Licensed User
Longtime User
Hi ThRuST:

Thanks to you for sharing.

I've tested the version you've attached, and it works for me in B4J (
In B4A I get this error during compilation: Can't find: C:\Program Files\Anywhere Software\B4A\libraries\jcore.jar.
 

agraham

Expert
Licensed User
Longtime User
Assuming you are trying to use B4XPassword.bas in B4A try opening it with Notepad++ or similar and change the first line

from
B4J=true

to
B4A=true

EDIT: Might not be required as I tried it without and seems OK. I can't get your error but you need to comment out in Sub Process_Globals
'Private fx As JFX
 
Last edited:

ThRuST

Well-Known Member
Licensed User
Longtime User
@agraham Thanks for pointing this out. It should be useful to compile the code module as a library, which I tried but then I could not access the method.
I'm not used to creating libraries so this is still a learning phase. Anyway, I hope you can help me. Still failing forward with B4X :)
 

josejad

Expert
Licensed User
Longtime User
Thanks agraham.

Sorry, I didn't explain it, I was using the .jar ThRuST sent me, not the .bas file...
 

ThRuST

Well-Known Member
Licensed User
Longtime User
How to turn the code module into a universal B4X library and access the methods? I compiled it in the B4J IDE with Project/Compile to Library ALT+5
 

ThRuST

Well-Known Member
Licensed User
Longtime User
@stevel05 Thanks, but where is the Manifest editor in B4J v9.50? I need to add these

lib:
Version=1.30
B4J.DependsOn=jXUI, jCore, jFX
B4A.DependsOn=XUI, jCore,  ?
B4i.DependsOn=iXUI, jCore, ?
 

stevel05

Expert
Licensed User
Longtime User
The Manifest file for a B4xlib is not the same as the Android Manifest file. Just create a text file called Manifest.txt with the content you need and include it in the zipped b4xlib.
 

ThRuST

Well-Known Member
Licensed User
Longtime User
Btw which libraries will be needed for B4A and B4i for this?

B4J

1656685447823.png


B4A

1656685352972.png


B4i

1656685405688.png
 

ThRuST

Well-Known Member
Licensed User
Longtime User
I assume this is correct to make a B4xlib

core:
Version=1.30
B4J.DependsOn=jXUI, jCore, jFX
B4A.DependsOn=XUI, Core
B4i.DependsOn=iXUI, jCore

1656685601142.png
 

stevel05

Expert
Licensed User
Longtime User
You don't need to specify the core libraries, but the others look OK. Build the library and test it in a new project.
 

ThRuST

Well-Known Member
Licensed User
Longtime User
This is what happened. Any suggestions?
I zipped the two files into a zip file using WinRAR. I put the file in B4J additional libraries folder.

1656686217760.png


1656686064639.png
 

Attachments

  • 1656685971459.png
    1656685971459.png
    46.1 KB · Views: 153

stevel05

Expert
Licensed User
Longtime User
If it's a CodeModule then you don't need to declare a variable for it. It should just be available.
 

ThRuST

Well-Known Member
Licensed User
Longtime User
Strange it's not working.I did like this. Is that really enough?

1656686697146.png

1656686829502.png
 

ThRuST

Well-Known Member
Licensed User
Longtime User
I have tried many combinations but it's not working, strange. I added my b4xlib in the first post.
I rest my case for now :)
 
Top