Python Forum
I need help using Python to generate usernames and passwords with excel documents
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need help using Python to generate usernames and passwords with excel documents
#1
Hey guys, I need some serious help and guidance with creating a script. I realize I'm well over my head here but I still feel somehow I'm on the verge of "making something great". Worth noting is I'm incredibly new to python modules.

So, what I want is a python script that takes the existing content out of 1 excel file (called names.xsl) and then creates a new excel file but with an additional 2 columns, Username & Password. Now I have a function that generates a random 8 letter password. But I also need a function that generates a username based upon their names and room number(Which anybody is welcome to come with suggestions how to solve).

Layout of names.xsl:
A , B ,C , D
Name, socialsecuritynr, room, tel
Amy Anderson, 12345678, 636, 070xxx
etc etc (there are 33 names)

Layout of names_mod.xsl:
A , B , C , D , E , F
Name, socialsecuritynr, room, tel, Username, Password
Amy Anderson, 12345678, 636, 070xxx, amy636, randpa55

 1 import pandas as pd 2 from pandas import ExcelWriter 3 from pandas import ExcelFile 4 import numpy as np 5 import xlsxwriter 6 7 import random 8 import string 9 10 def randompassword(stringLength=6): 11 lettersAndDigits = string.ascii_letters + string.digits 12 return ''.join(random.choice(lettersAndDigits) for i in range(stringLength)) 13 print (randompassword(8)) 14 15 df = pd.read_excel('names.xls', sheet_name='Sheet1') 16 17 workbook = xlsxwriter.Workbook('names_mod.xls') 18 worksheet = workbook.add_worksheet() 19 20 worksheet.write('E1', 'Username') 21 worksheet.write('F1', 'Password') 22 worksheet.write('F2-34',(randompassword(8)) 23 workbook.close() 24 25 df1 = pd.read_excel('names_mod.xls', sheet_name='Sheet1') 26 print(df1) 
I realize this is A LOT to ask and the whole sript is a complete mess at the moment.. but any help is muchly appreciated, I've been at this for a good week now and could really use some help. Please let me know if I'm breaking any forum rules or need to clarify anything. Thanks in advance.
Reply
#2
To get the username from
Output:
Amy Anderson, 12345678, 636, 070xxx
to
Output:
amy636
Use split on the name and pair it with room.
Reply
#3
Any chance you could be more specific? I know how to use split, just not when there's an excel file involved.
Reply
#4
Hey guys, I'm incredibly new to Python and even more so to its modules.

I have an excel file (names.xsxl) with 33 names and info. I'm trying to create a script that generates a random username as well as a password for each user in the 'E' and 'F' column respectively. How would I do this with the help of my two functions?


I hope I'm making myself clear, if I'm not, don't hesitate to ask for a clarification. Here's my code so far:

 1 import random 2 import string 8 from openpyxl import workbook 9 from openpyxl import load_workbook 10 import xlrd 11 12 wb = load_workbook('names.xlsx') #reads the names.xlsx file 13 wb.save('names_mod.xlsx') #saves it with the name: names_mod.xslx 14 15 def randompassword(stringLength=8): #creates a random password 16 lettersAndDigits = string.ascii_letters + string.digits 17 return ''.join(random.choice(lettersAndDigits) for i in range(stringLength)) 18 19 def username(stringLength=5): #creates a random username 20 lettersAndDigits = string.ascii_letters + string.digits 21 return ''.join(random.choice(lettersAndDigits) for i in range(stringLength))
Thankful for any help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Extracting parts of paragraphs from word documents using python-docx library & lists Den0st 1 26,259 Oct-08-2025, 05:56 AM
Last Post: OtiliaGen
  Know nothing about python need to generate pdf Borracha22 11 8,290 Aug-01-2025, 12:15 AM
Last Post: Pedroski55
  Help with Python Script to generate SVG Dot Matrix Pattern for LED Light Guide iamrickm 2 2,476 Aug-25-2023, 06:07 PM
Last Post: iamrickm
  Word documents merging crewdk 1 4,752 Apr-03-2023, 06:32 AM
Last Post: buran
  best way to embed passwords into scripts mikey6785 3 6,135 Aug-31-2022, 08:22 AM
Last Post: DeaD_EyE
  Generate Python variables dynamically Pedroski55 5 6,511 Mar-04-2022, 10:13 PM
Last Post: deanhystad
  Encrypting Oracle Passwords / Python Library for That? bmccollum 1 4,152 Jun-11-2021, 07:59 PM
Last Post: Larz60+
  Сombine (Merge) word documents using python-docx Lancellot 1 18,245 May-12-2021, 11:07 AM
Last Post: toothedsword
  Copy documents to Teams using python SallySmith 0 3,498 Mar-23-2021, 04:27 AM
Last Post: SallySmith
Question Mouseover(Hover/Float) text in PDF documents ak52 1 3,916 Feb-24-2021, 06:13 PM
Last Post: nilamo

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.