Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Stud.IP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan-Hendrik Willms
Stud.IP
Commits
6450ece8
Commit
6450ece8
authored
11 months ago
by
Marcus Eibrink-Lunzenauer
Browse files
Options
Downloads
Patches
Plain Diff
Add `ChangePassword` CLI script.
Closes #3896 Merge request
studip/studip!2754
parent
a4907198
No related branches found
No related tags found
Loading
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cli/Commands/User/ChangePassword.php
+95
-0
95 additions, 0 deletions
cli/Commands/User/ChangePassword.php
cli/studip
+1
-0
1 addition, 0 deletions
cli/studip
with
96 additions
and
0 deletions
cli/Commands/User/ChangePassword.php
0 → 100644
+
95
−
0
View file @
6450ece8
<?php
namespace
Studip\Cli\Commands\User
;
use
email_validation_class
;
use
StudipLog
;
use
Symfony\Component\Console\Command\Command
;
use
Symfony\Component\Console\Input\InputArgument
;
use
Symfony\Component\Console\Input\InputOption
;
use
Symfony\Component\Console\Input\InputInterface
;
use
Symfony\Component\Console\Output\OutputInterface
;
use
Symfony\Component\Console\Helper\Table
;
use
Symfony\Component\Console\Question\Question
;
use
UserManagement
;
/**
* @SuppressWarnings(PHPMD.StaticAccess)
*/
class
ChangePassword
extends
Command
{
protected
static
$defaultName
=
'user:password'
;
protected
function
configure
():
void
{
$this
->
setDescription
(
'Change the password of a Stud.IP user.'
);
$this
->
setHelp
(
'This command will change the password of a user.'
);
$this
->
addArgument
(
'username'
,
InputArgument
::
REQUIRED
,
'The username of the user whose password will be changed.'
);
}
protected
function
execute
(
InputInterface
$input
,
OutputInterface
$output
)
{
$username
=
$input
->
getArgument
(
'username'
);
$user
=
\User
::
findOneBySQL
(
'username = ?'
,
[
$username
]);
if
(
!
$user
)
{
$output
->
writeln
(
'<error>Could not find this user.</error>'
);
return
Command
::
FAILURE
;
}
$helper
=
$this
->
getHelper
(
'question'
);
$question
=
new
Question
(
'New password: '
,
''
);
$question
->
setHidden
(
true
);
$password
=
$helper
->
ask
(
$input
,
$output
,
$question
);
$question2
=
new
Question
(
'Re-type password: '
,
''
);
$question2
->
setHidden
(
true
);
$password2
=
$helper
->
ask
(
$input
,
$output
,
$question2
);
$status
=
$this
->
changePassword
(
$user
,
$password
,
$password2
);
if
(
isset
(
$status
))
{
$output
->
writeln
(
'<error>'
.
$status
.
'</error>'
);
return
Command
::
FAILURE
;
}
return
Command
::
SUCCESS
;
}
private
function
changePassword
(
\User
$user
,
string
$password
,
string
$password2
)
:
?
string
{
if
(
$password
!==
$password2
)
{
return
'Password and re-type password don\'t match.'
;
}
$validator
=
new
email_validation_class
();
$validator
->
timeout
=
10
;
if
(
!
$validator
->
ValidatePassword
(
$password
))
{
return
'The password is too short. It should have at least 8 characters.'
;
}
if
(
$password
===
$user
->
username
)
{
return
'Password may not match the username.'
;
}
if
(
str_replace
([
'.'
,
' '
],
''
,
mb_strtolower
(
$password
))
==
'studip'
)
{
return
'For security reasons the password may not be "Stud.IP" or any modification of "Stud.IP".'
;
}
$userManagement
=
new
UserManagement
(
$user
->
id
);
$changed
=
$userManagement
->
changePassword
(
$password
);
if
(
!
$changed
)
{
return
'The password could not be set.'
;
}
StudipLog
::
USER_NEWPWD
(
$user
->
id
,
null
,
'Passwort neu gesetzt'
,
null
,
$user
->
id
);
return
null
;
}
}
This diff is collapsed.
Click to expand it.
cli/studip
+
1
−
0
View file @
6450ece8
...
@@ -60,6 +60,7 @@ $commands = [
...
@@ -60,6 +60,7 @@ $commands = [
Commands\Resources\UpdateBookingIntervals
::
class
,
Commands\Resources\UpdateBookingIntervals
::
class
,
Commands\SORM\DescribeModels
::
class
,
Commands\SORM\DescribeModels
::
class
,
Commands\Twillo\PrivateKeys
::
class
,
Commands\Twillo\PrivateKeys
::
class
,
Commands\User\ChangePassword
::
class
,
Commands\User\GetUser
::
class
,
Commands\User\GetUser
::
class
,
Commands\User\UsersDelete
::
class
,
Commands\User\UsersDelete
::
class
,
];
];
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment