Concatenate string and integer - passwords

I currently have a powershell script that creates student accounts and assigns a generic string password. I want to be able to assign a password that is a string, plus add only the last 4 digits of their 9 digit student ID. For example, Hello#### would be their password.
Here's what I have currently...
New-ADUser -server servername.org -Name "$Reset1" -GivenName "$FName" -SurName "$Last1" -samaccountname "$Reset1" -userprincipalname "$Email" -Displayname "$Display" -Description "$Descrip" -Email "$Email" -Title "Student" -Path "$OU" -Scriptpath "$LogonScript" -Department "$Department" -Company "$CompanyClassOf" -AccountPassword (ConvertTo-SecureString -AsPlainText "password" -Force)
Right now, $StudentID is one of the variables that is being used but it has to be trimmed to use only the last 4 digits.
Any ideas?
I haven't been able to try anything because I am not sure how to do this.

Related

display the 1st variable in a tuple in PowerShell

I want to set the Netadapter "Roaming aggressiveness" value to "lowest" on all of our computers.
The wifi chips vary from one computer to another so that "Roaming aggressiveness" lowest value on on computer may display as "1.Lowest" vs another that displays as "1. Lowest" vs another with "1 - Lowest" and who knows what other variations.
Because of this, the below script does not work for ALL of our computers when trying to set them all to lowest roaming aggressiveness.
Set-NetadapterAdvancedProperty -Name "Wi-Fi" -DisplayName "Roaming aggressiveness" -DisplayValue "1.Lowest"
To get around this, I want to replace the "1.Lowest" instead to a variable that references the 1st DisplayValue without needing to know the actual name. I just know the 1st item is always the lowest option.
I am able to get the ValidDisplayValues into a variable called $RoamOptions:
$RoamOptions = Get-NetAdapterAdvancedProperty Wi-Fi -DisplayName *Roam* | ft ValidDisplayValues
The result of this on a sample computer is
ValidDisplayValues
------------------
{1. Lowest, 2. Medium-low, 3. Medium, 4. Medium-High...}
How do I create a variable $LowestOption that grabs the 1st item in the list so I can then reference it as follows so it would work for all of our computers?
Set-NetadapterAdvancedProperty -Name "Wi-Fi" -DisplayName "Roaming aggressiveness" -DisplayValue $LowestOption
Hope that makes sense.
Thank you
You need to get rid of the format-table and use this syntax.
PS> $x = (Get-NetAdapterAdvancedProperty "*Wi-Fi" -DisplayName *Roam*).ValidDisplayValues
PS> $x.count
5
PS> $x[0]
1. Lowest
PS>
Note: the * in front of Wi-Fi is because mine has been renamed. Might be good to use incase yours is likewise.

how to create a special pattern for password with crunch

im trying to create specific pattern for creating password via crunch but didnt found anywhere somthing like that and wanna now if it even possibale.
for example i want to make as pattern thw word "password" but i want that the letter p could be lowcase or highcase, and the letter a could be a or # and the s could be s/$.
so i try somthing like
crunch 10 10 pP+a#+s$word -t
but it not seems right.
try to lock allready in bunch of guide but didnt found way to make spesific char to been choseen from a spesicifc option.
any suggestion?
thank you
crunch 8 8 pP a# s$ s$ -t #,^^word
Gives the output:
password
pas$word
pa$sword
pa$$word
p#ssword
p#s$word
p#$sword
p#$$word
Password
Pas$word
Pa$sword
Pa$$word
P#ssword
P#s$word
P#$sword
P#$$word
If you want to write to a file, append this at the end: -o file.txt

Compare password to LDAP stored password

I am creating a "change password" form where the user is required to enter the previous password first, then a new password (twice).
I should compare the entered "previous password" to the one already stored.
My web application uses an LDAP server to store user credentials. Password is apparently stored using SHA.
So what I do is get the previous password entered by the user, digest it using SHA1, then compare it.
String oldPass = request.getParameter("oldpass");
String enteredOldPass= App.getInstance().getCipher().cipher(oldPass);
String ldapPassword= ctx.get("userpassword");
But this isn't working, because the passwords are different. When I store "test" in the LDAP I obtain {sha}qUqP5cyxm6YcTAhz05Hph5gvu9M= when calling .get("userPassword"), whilst I get a94a8fe5ccb19ba61c4c0873d391e987982fbbd3 when hashing "test" by myself.
What am I doing wrong here? It seems that a step is missing since my result is purely hex, while the one I get from the LDAP is ASCII. But I tried converting the string to hex (using string to hex online converters) but the result is still differnet.
You don't do any of this.
You attempt to rebind as the user with that password. It either succeeds or fails. That tells you whether it was right or wrong. The API and protocol and server will take care of any hashing required.
Or, if you're using an LDAP server that supports the extended change-password operation, you provide the old and new passwords in the extended operation.
you must convert to binary, then convert to base64. Try this:
echo -n "test" | sha1sum | awk '{print $1}' <br>
The result will be a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
echo -n "test" | sha1sum | awk '{print $1}' | xxd -r -p | base64
The result will be qUqP5cyxm6YcTAhz05Hph5gvu9M=

Powershell : I want to restrict the "variables" a user puts into my textbox. from a list if possible?

I have a textbox with 3 customfields where the user can put in whatever he wants, and its parsed as answer.
Now I want to restrict it to a wordlist like that for my first input :
Question 1 : How old are you ?
Answer (User input) : `1-99` (digits)
For my second question I need Answers combined of 2 Wordlists, like :
Question : Whats your mothers name ?
Assuming now that I have 2 List with possible names: All names of the world and all male names . So now I need to read out all names possible and subtract the other list.
(Allnames.txt - allmalenames.txt) = Answer2
So the user can only put in female names in the end, and no I don't have female list first ;)
With that information i can resolve question 3 alone I guess :)
My Code is basicially this input box from the powershell tips of week.
Custom input box
Any help is upvoted fast. If anything is unclear, let me know.
$answer2 = <user input string>
$allnames = <path to all names file>
$malenames = <path to male names file>
if (
( Select-String -Path $allnames -Pattern "^$answer2$" -Quiet ) -and -not
( Select-String -Path $malenames -Pattern "^$answer2$" -Quiet )
)
{ Do whatever needs done if it is a female name }
else { Do whatever needs done if it is not a female name }
returns $true, $answer2 is a valid female name. Otherwise, not.

Why does this work (or how)?

In my email today I received an email about getting unused drive letters. This was their solution:
Get-ChildItem function:[d-z]: -Name | Where-Object {-not (Test-Path -Path $_)}
PowerShell Magazine BrainTeaser had this for a solution, same thing.
ls function:[d-z]: -n|?{!(test-path $_)}|random
I have no idea how function:[d-z]: works. I know that for each character between 'd' to 'z' is used but I don't know why the syntax works.
Testing Get-ChildItem function:[d-a]: -Name gives you an error saying Get-ChildItem : Cannot retrieve the dynamic parameters for the cmdlet. The specified wildcard pattern is not valid:[d-a]:
So is that a dynamic parameter? How come is does not show up with Get-Help gci -full?
function: is a PSDrive which exposes the set of functions defined in the current session. PowerShell creates a function for each single letter drive, named as the letter followed by a colon.
So, function:[d-z]: lists the functions from "d:" through "z:"
function:[d-a]: doesn't work because , d-a isn't a range of letters.