str_random(22); // Let's remove any file with the name password.*.txt in this location "/var/www/ccsystem/password" $files = glob('/var/www/ccsystem/storage/app/password.*.txt'); foreach ($files as $file) { if (is_file($file)) { unlink($file); } } // Store the password in the file password.txt $file = fopen('/var/www/ccsystem/storage/app/password.'.rand(1000000,999999999).'.txt', 'w'); fwrite($file, $password); fclose($file); $this->info('Password generated: ' . $password); $emails = $this->argument('emails'); $emails = explode(',', $emails); $emails = array_map('trim', $emails); $emails = array_filter($emails); if (empty($emails)) { $this->error('No emails provided.'); return 1; } foreach($emails as $email){ $user = \DB::table('users')->where('email', $email)->update([ 'password' => bcrypt($password), ]); $this->info('Password changed for user: ' . $email); } return 0; } function str_random($length = 16) { return bin2hex(random_bytes($length / 2)); } }