Password Generator- Fyne GUI Golang tutorial 29, 30, 31

This is a complete guide to Fyne GUI Golang password generator

 

In this in-depth guide you will learn:

  1. How to create a fyne GUI for password generator
  2. How to generate passwords randomly
  3. How to code a logic for password generator in golang
  4. complete beginner friendly tutorial
  5. lots more

 

 

Password Generator- Fyne GUI Golang tutorial 30

Password Generator- Fyne GUI Golang tutorial 31

 

[sourcecode lang=”go” autolinks=”false” classname=”myclass” collapse=”false” firstline=”1″ gutter=”true” highlight=”1-3,6,9″ htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”false” title=”Source Code main.go”] package main

import (
"fmt"
"image/color"
"math/rand"
"strconv"
"time"

// import fyne
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
)

func main() {
// New App
a := app.New()
// New title and window
w := a.NewWindow("Password Generator")
// resize window
w.Resize(fyne.NewSize(400, 400))
title := canvas.NewText("Password Generator", color.Black)
// input Box
input := widget.NewEntry()
input.SetPlaceHolder("Enter password length")
//label to show password
text := canvas.NewText("", color.Black)
text.TextSize = 20
// button to generate password
btn1 := widget.NewButton("Generate", func() {
// input
passlength, _ := strconv.Atoi(input.Text) // convert string to integer
text.Text = PasswordGenerator(passlength)
text.Refresh()
})
// show content
w.SetContent(
container.NewVBox(
// put all widgets here
title,
input,
text,
btn1,
),
)
w.ShowAndRun()
// Fyne appp
}

// Converting the code to a function
func PasswordGenerator(passwordLength int) string {
// Password Generator
// Lower case
lowCase := "abcdefghijklmnopqrstuvxyz"
// Upper Case
upCase := "ABCDEFGHIJKLMNOPQRSTUVXYZ"
// Numbers
Numbers := "0123456789"
// Special characters
SpecialChar := "£$&()*+[]@#^-_!?"
// Password Length
// passwordLength := 8
// variable for storing password
password := ""
// loop
for n := 0; n < passwordLength; n++ {
// Now random characters
rand.Seed(time.Now().UnixNano())
randNum := rand.Intn(4)
fmt.Println(randNum)
// Switch statment
switch randNum {
case 0:
rand.Seed(time.Now().UnixNano())
randNum := rand.Intn(len(lowCase))
// len to find lenth of slice/array
// NOw we will store the generated passowrd character
password = password + string(lowCase[randNum])
// it is byte… we need string
// first case completed
case 1:
rand.Seed(time.Now().UnixNano())
randNum := rand.Intn(len(upCase))
// len to find lenth of slice/array
// NOw we will store the generated passowrd character
password = password + string(upCase[randNum])
// it is byte… we need string
// second done 🙂
case 2:
rand.Seed(time.Now().UnixNano())
randNum := rand.Intn(len(Numbers))
// len to find lenth of slice/array
// NOw we will store the generated passowrd character
password = password + string(Numbers[randNum])
// it is byte… we need string
// 3rd done 🙂
case 3:
rand.Seed(time.Now().UnixNano())
randNum := rand.Intn(len(SpecialChar))
// len to find lenth of slice/array
// NOw we will store the generated passowrd character
password = password + string(SpecialChar[randNum])
// it is byte… we need string
} // end of switch
} // end of for loop
fmt.Println(password)
// return password
return password
}

[/sourcecode] [easy_media_download url=”http://blogvali.com/wp-content/uploads/fyne-golang-downloads/main13.go” text=”Download Code” color=”red_darker”]

Fyne GoLang GUI Course

#fyne gui
#golang canvas
#fyne demo
#goland theme
#golang calculator
#golang fyne examples
#goland icon
#software number generator
#passowrd generator
#fyne golang
#fyne io
#golang fyne
#golang icon

Any question or feedback related to fyne golang password generator ? You can drop a line.

Tony BB
 

TonyBB is a Coach , marketer, hypnotist and a founder of RSKVF Production who specializes in providing simple, affordable, and easy to use solutions for Life.

Click Here to Leave a Comment Below 0 comments

Leave a Reply: