Skip to content
Snippets Groups Projects
Commit 886a17a0 authored by Ghassane Ben El Aattar's avatar Ghassane Ben El Aattar Committed by ghassaneben
Browse files

oniro-user: Script that allows to edit the default password


This python script allows the user to edit the default password,
by modifying the local.conf file (the path has to be specified).

Signed-off-by: default avatarGhassane Ben El Aattar <ghassaneb.aattar@huawei.com>
parent db7e0150
No related branches found
No related tags found
No related merge requests found
Pipeline #10936 failed
# SPDX-FileCopyrightText: Huawei Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# Allows to change default password through interaction or command line arguments
from getpass import getpass
import pwd
import crypt
import sys
arguments = sys.argv
path = ""
password = ""
#if the arguments are inserted, the interaction is not used; the arguments are the local.conf path and new password; arguments[0] is the python script name
if(len(arguments) == 3):
path = arguments[1]
password = arguments[2]
else:
print('Insert path to your local.conf file: ')
path = input()
print('Insert new password: ')
password = getpass()
#SHA512 encryption of the password
crypt.METHOD_SHA512
password = crypt.crypt(password)
#insert slash before each $ character in the encrypted password, otherwise it won't work
single_slash2 = "\ "[0]
addSlash = []
pushedRight = 0
for i in range(0,len(password)):
if(password[i] == '$'):
addSlash.append(i)
for pos in addSlash:
password = password[:pos + pushedRight] + single_slash2 + password[pos + pushedRight:]
pushedRight = pushedRight + 1
#read the file and replace the username and password with the newly inserted values
alreadyExistPassword = 0
with open(path,'r' ) as file:
data = file.readlines()
index = 0
for line in data:
correctLinePassword = 0
for word in line.split(" "):
if(word == 'DEFAULT_USER_PASSWORD'):
correctLinePassword = 1
alreadyExistPassword = 1
break
if(correctLinePassword == 1):
data[index] = 'DEFAULT_USER_PASSWORD ?= '+ '"' +password +'"'+ '\n'
index = index + 1
if(alreadyExistPassword == 0):
data.append('DEFAULT_USER_PASSWORD ?= '+ '"' +password +'"'+ '\n')
#apply changes to local.conf file
with open(path, 'w') as file:
file.writelines(data)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment