File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Uchu.Core/Handlers/Commands Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,36 @@ public static string AddUser(string[] arguments)
85
85
return $ "\n Successfully added user: { name } !";
86
86
}
87
87
88
+ [ CommandHandler ( Signature = "resetpassword" , Help = "Reset a user's password" ) ]
89
+ public static string ResetPassword ( string [ ] arguments )
90
+ {
91
+ if ( arguments == null )
92
+ throw new ArgumentNullException ( nameof ( arguments ) ,
93
+ "arguments cannot be null" ) ;
94
+
95
+ if ( arguments . Length != 1 )
96
+ return "resetpassword <username>" ;
97
+
98
+ var username = arguments [ 0 ] ;
99
+
100
+ using var ctx = new UchuContext ( ) ;
101
+ var user = ctx . Users . FirstOrDefault ( u => string . Equals ( u . Username . ToUpper ( ) , username . ToUpper ( ) ) ) ;
102
+
103
+ if ( user == null )
104
+ return "No user with that username exists" ;
105
+
106
+ Console . Write ( "New password: " ) ;
107
+ var password = GetPassword ( ) ;
108
+
109
+ if ( password . Length > 42 )
110
+ return "\n Passwords with more than 42 characters are not supported" ;
111
+
112
+ user . Password = BCrypt . Net . BCrypt . EnhancedHashPassword ( password ) ;
113
+ ctx . SaveChanges ( ) ;
114
+
115
+ return $ "\n Successfully reset password for user: { user . Username } !";
116
+ }
117
+
88
118
[ CommandHandler ( Signature = "removeuser" , Help = "Remove a user" ) ]
89
119
public static string RemoveUser ( string [ ] arguments )
90
120
{
You can’t perform that action at this time.
0 commit comments