Cursussen/Courses Codesnippets     Top 
B4A-JSON - B4A password tool


1. Layout
Sometimes you need to generate a password or a hard to guess variable name (like in the lists_JSON.php file). With this tool you can generate a string of random letters and numbers. To avoid confusion some letters and numbers are omitted.
Make a new default project, give it a good name, add the layout and the code and there you have it!
With the XUI Views library you can use the B4X components.
Don"t forget to generate the members!


2. Code
And this is the code you can use:
The app doesn't handle the landscape orientation correctly. So change the SupportedOrientations to portrait.
#Region  Project Attributes 
	#ApplicationLabel: Password generator
	#VersionCode: 1
	#VersionName: 
	'SupportedOrientations possible values: unspecified, landscape or portrait.
	#SupportedOrientations: portrait
	#CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.
	Private xui As XUI
End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	Private B4XSeekBar1 As B4XSeekBar
	Private Button1 As Button
	Private ftf1 As B4XFloatTextField
	Private Label1 As Label
	Private Panel1 As Panel
	Private lblnumber As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
	Activity.LoadLayout("Layout")
	Activity.Title = "Password generator"
	ftf1.Text = ""
End Sub

Sub Activity_Resume
	B4XSeekBar1.Value = 8
	lblnumber.Text = 8
	ftf1.Text = ""
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
	generate_password
End Sub

Private Sub B4XSeekBar1_ValueChanged (Value As Int)
	lblnumber.Text = B4XSeekBar1.Value
End Sub

Private Sub generate_password
	Dim ww As String
	Dim kar As String
	Dim pos As Int
	Dim abc As String = "abcdefghjkmnpqrstuvwxyz23456789ABCDEFGHJKLMNPQRSTUVWXYZ"
	Dim aantal As Int = lblnumber.Text
	For i = 1 To aantal
		pos = Rnd(1,abc.Length-1)
		kar = abc.SubString2(pos,pos+1)
		ww = ww & kar
	Next
	ftf1.Text = ww
	Log(ww)
End Sub


X

Paragrafen

1. Layout 2. Code