Skip to main content
Solved

Random Password Generator: password always starts with letter

  • March 4, 2021
  • 1 reply
  • 55 views

fikusas
Contributor
Forum|alt.badge.img+5

How can I force that first symbol of generated passwords always be letter? I'm using this:

import fmeobjects
import random
import string
 
def processFeature(feature):
    length = int(FME_MacroValues['Lenght'])
    
    letters = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'
    digits = '123456789'
    symbols = '!#$%*+-:;<=>?'
    all = letters + digits + symbols
    temp = random.sample(all,length)
    
    password = "".join(temp)
    feature.setAttribute('Password', password)

 

Best answer by david_r

Suggestion:

temp = random.sample(letters, 1) + random.sample(all, length-1)

 

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

1 reply

david_r
Celebrity
  • Best Answer
  • March 4, 2021

Suggestion:

temp = random.sample(letters, 1) + random.sample(all, length-1)