I am using password_hash function to insert hash into database as part of user registration. This works well and a password hash is created in the database. However, I am unable to verify the password using password_verify, with the check always returning false. For example:
$hash = password_hash("rattle",PASSWORD_DEFAULT)
returns `$hash = $2y$10$fonFqdioDtfJ/Gp7t4orWOdalMHkKQSA8PrFvbgI7LC0LCvYshZ.i`
This is successfully inserted into the database. However, password_verify('rattle',$hash) always returns false. I have tried echoing the hash before it is inserted into the database and using that as the hash, but still no joy. The database hash field is setup as 60 char.
Any help will be greatly appreciated.
Tested, works on both saved string and dynamic. Always 60 chars.
$hash = password_hash("rattle",PASSWORD_DEFAULT);
$hashCheckSaved = password_verify("rattle", '$2y$10$KDIzEQjsmlHCP0mjixbBoe9yJE8tY4aNPOZegiwez1zUPkt5217M2');
$hashCheckDynamic = password_verify("rattle", $hash);
echo $hash."<br> saved(". $hashCheckSaved . ") dynamic(". $hashCheckDynamic.")";
echo "<br>";
echo strlen($hash) . " chars in this string";
Related
This code insert the record into the basetable without alert.
CurrentDb.Execute _
"INSERT INTO basetable(clName,clId,clGender) VALUES('test','123','');"
I expected this code should pop alert up because the clGender field set to be "required", but no alert. Could you please tell me where I was wrong.
You can use:
DoCmd.RunSQL " Insert ... "
though that may be too much.
The reason you didn't get an alert is because you supplied a value for clGender. In table design view there are two relevant properties: Required and Allow zero length. Your clGender field has both of these set to true. The Required setting means that you can't save the record with this field as Null but in your insert statement you haven't specified Null, you've specified an empty string, which is allowed by the Allow zero length setting.
[EDIT]
Sorry, just realised what's going on. The Execute method doesn't give you any feedback directly. However you can use the RecordsAffected property to see if it did what you expected.
Dim db As DAO.Database
Set db = CurrentDb()
db.Execute "INSERT INTO basetable(clName,clId,clGender) VALUES('test','123','')"
If db.RecordsAffected = 0 Then
MsgBox "Insert failed"
End If
Set db = Nothing
I have scraped data from a website and entered it into an array using the code below:
def process_course_details(course_details)
details_array =[]
details_link = true
entry_link = true
details_info = {}
# Sets all data in hash
details_info[:url] = clean_link(course_details.search('div.coursedetails_programmeurl a'))
details_array.push(details_info)
print_details_info(details_info)
entry_link = course_details.search('ul.details_tabs').first
end
The code above stores the element being pulled as such:
View course details on provider's website
But I'd like to clean the above to the below:
http://www.abdn.ac.uk/study/courses/undergraduate/C8R1/
or failing that remove the apostrophe and have this:
View course details on providers website`
You can extract the href with Nokogiri like this:
html = Nokogiri::HTML('View course details on provider\'s website')
html.xpath("//a/#href").to_s # => "http://www.abdn.ac.uk/study/courses/undergraduate/C8R1/"
Based on your comment:
When storing other data I've scraped into the database the apostrophe
provided errors and stopped it. Once I had cleaned the apostrophe and
it no longer was part of the array the code worked and the table was
created.
db = SQLite3::Database.open('ahhh.sqlite3')
db.execute "INSERT INTO aahah (uname, cname, duration, qualification, url, entry) VALUES ('#{#uni_name}', #{#course_name}', '#{#course_duration}', '#{#course_qual}', '#{#details_entry}', '#{#requirements}')"
You are inserting the values via string interpolation:
db.execute("INSERT INTO table_name (foo, bar) VALUES ('#{#foo}', '#{#bar}')")
Apparently, if the interpolated strings contain an apostrophe, your SQL string likely becomes invalid. Even worse, this code is prone to SQL injection.
Instead you should use parameter markers and let the SQLite gem handle the escaping:
db.execute("INSERT INTO table_name (foo, bar) VALUES (?, ?)", [#foo, #bar])
This allows you to safely insert apostrophe and other special characters.
I need to read a file where the content is like below :
Computer Location = afp.local/EANG
Description = RED_TXT
Device Name = EANG04W
Domain Name = afp.local
Full Name = Admintech
Hardware Monitoring Type = ASIC2
Last Blocked Application Scan Date = 1420558125
Last Custom Definition Scan Date = 1348087114
Last Hardware Scan Date = 1420533869
Last Policy Sync Date = 1420533623
Last Software Scan Date = 1420533924
Last Update Scan Date = 1420558125
Last Vulnerability Scan Date = 1420558125
LDAP Location = **CN=EANG04W**,OU=EANG,DC=afp,DC=local
Login Name = ADMINTECH
Main Board OEM Name = Dell Inc.
Number of Files = 384091
Primary Owner = **CN= LOUHICHI anoir**,OU=EANG,DC=afp,DC=localenter code here
I need to replace CN=$value by CN=Compagny where $value is what is retrived after CN= and before ,.
Ok, so you really should have updated your question an not posted the code in a comment, because it's really hard to read. Here's what I think you intended:
$file = 'D:\sources\scripts\2.txt'
$content = Get-Content $file | foreach ($line in $content) {
if ($line.Contains('CN=')) {
$variable = $line.Split(',').Split('=')[2]
$variable1 = $variable -replace $variable, "Compagny"
} Set-Content -path $file
}
That deffinately has some syntax errors. The first line is great, you define the path. Then things go wrong... Your call to Get-Content is fine, that will get the contents of the file, and send them down the pipe.
You pipe that directly into a ForEach loop, but it's the wrong kind. What you really want there is a ForEach-Object loop (which can be confusing, because it can be shortened to just ForEach when used in a pipeline like this). The ForEach-Object loop does not declare an internal variable (such as ($line in $content)) and instead the scriptblock uses the automatic variable $_. So your loop needs to become something like:
Get-Content $file | ForEach { <do stuff> } | Set-Content
Next let's look inside that loop. You use an If statement to see if the line contains "CN=", understandable, and functional. If it does you then split the line on commas, and then again on equals, selecting the second record. Hm, you create an array of strings anytime you split one, and you have split a string twice, but only specify which record of the array you want to work with for the second split. That could be a problem. Anyway, you assign that substring to $variable, and proceed to replace that whole thing with "company" and store that output to $variable1. So there's a couple issues here. Once you split the string on the commas you have the following array of strings:
"LDAP Location = **CN=EANG04W**"
"OU=EANG"
"DC=afp"
"DC=local"
That's an array with 4 string objects. So then you try to split at least one of those (because you don't specify which one) on the equals sign. You now have an array with 4 array objects, where each of those has 2 string objects:
("LDAP Location", "**CN", "EANG04W**")
("OU", "EANG")
("DC","afp")
("DC","local")
You do specify the third record at this point (arrays in PowerShell start at record 0, so [2] specifies the third record). But you didn't specify which record in the first array so it's just going to throw errors. Let's say that you actually selected what you really wanted though, and I'm guessing that would be "EANG04W". (by the way, that would be $_.Split(",")[0].Split("=")[1]). You then assign that to $Variable, and proceed to replace all of it with "Company", so after PowerShell expands the variable it would look like this:
$variable1 = "EANG04W" -replace "EANG04W", "company"
Ok, you just successfully assigned "company" to a variable. And your If statement ends there. You never output anything from inside your If statement, so Set-Content has nothing to set. Also, it would set that nothing for each and every line that is piped to the ForEach statement, re-writing the file each time, but fortunately for you the script didn't work so it didn't erase your file. Plus, since you were trying to pipe to Set-Content, there was no output at the end of the pipeline, you have assigned absolutely nothing to $content.
So let's try and fix it, shall we? First line? Works great! No change. Now, we aren't saving anything in a variable, we just want to update a file's content, so there's no need to have $Content = there. We'll just move on then, shall we? We pipe the Get-Content into a ForEach loop, just like you tried to do. Once inside the ForEach loop, we're going to do things a bit differently though. The -replace method performs a RegEx match. We can use that to our advantage here. We will replace the text you are interested in for each line, and if it's not found, no replacement will be made, and pass each line on down the pipeline. That will look something like this for the inside of the ForEach:
$_ -replace "(<=CN\=).*?(?=,)", "Company"
The breakdown of that RegEx match can be seen here: https://regex101.com/r/gH6hP2/1
But, let's just say that it looks for text that has 'CN=' immediately before it, and goes up to the first comma following it. In your example, that includes the two trailing asterisks, but it doesn't touch the leading ones. Is that what you intended? That would make the last line of your example file:
Primary Owner = **CN=Company,OU=EANG,DC=afp,DC=localenter code here
Well, if that is as intended, then we have a winner. Now we close out the ForEach loop, and pipe the output to Set-Content and we're all set! Personally, I would highly suggest outputting to a new file, in case you need to reference the original file for some reason later, so that's what I'm going to do.
$file = 'D:\sources\scripts\2.txt'
$newfile = Join-Path (split-path $file) -ChildPath ('Updated-'+(split-path $file -Leaf))
Get-Content $file | ForEach{$_ -replace "(?<=CN\=).*?(?=,)", "Company"} | Set-Content $newfile
Ok, that's it. That code will produce D:\sources\scripts\Updated-2.txt with the following content:
Computer Location = afp.local/EANG
Description = RED_TXT
Device Name = EANG04W
Domain Name = afp.local
Full Name = Admintech
Hardware Monitoring Type = ASIC2
Last Blocked Application Scan Date = 1420558125
Last Custom Definition Scan Date = 1348087114
Last Hardware Scan Date = 1420533869
Last Policy Sync Date = 1420533623
Last Software Scan Date = 1420533924
Last Update Scan Date = 1420558125
Last Vulnerability Scan Date = 1420558125
LDAP Location = **CN=Company,OU=EANG,DC=afp,DC=local
Login Name = ADMINTECH
Main Board OEM Name = Dell Inc.
Number of Files = 384091
Primary Owner = **CN=Company,OU=EANG,DC=afp,DC=localenter code here
I am still very new to Zend and running into some issues on exporting my data to a CSV.
I found a great resource that explains the headers and download part here however I am running into issues when trying to export the actual data.
If I create a variable like $content = "test" the export works fine using the code above.
However when I duplicate my indexAction code, make some changes, and bring it into my downloadAction, I am getting issues that I believe are due to my content being returned as an Object rather than an array or string.
My Module is grabbing the SQL by using:
public function fetchAllMembers($order = null , $order_by = null, $selectwhere = null) {
$session = new SessionContainer('logggedin_user');
$sql = new Sql($this->adapter);
$select = new Select();
$select->from(array('u' => 'tbl_all_data'));
if ($selectwhere != null){
$select->where($selectwhere);
}
$select->order($order_by . ' ' . $order);
$selectString = $sql->getSqlStringForSqlObject($select);
$results = $this->adapter->query($selectString, Adapter::QUERY_MODE_EXECUTE);
$results->buffer();
return $results;
}
and my Controller is calling that SQL by using:
$content = $modulesTable->fetchAllMembers($order, $order_by, $where);
Any help would be greatly appreciated, and I don't need anyone to write the code for me just help with pointoing me in the right direction.
$this->adapter->query returns a Zend\Db\ResultSet object. So you need to call $results = $results->toArray(); to send an array.
Also you need to loop through the array and echo it out in your view file.
Results, returned by adapter are ResultSet type. I guess you need to call at least
current()
method to grab some data. And they will be of array type, so, again you need to do something with them.
toArray() is often used to quickly get data.
More sophisticated way to get data, is to use next() method with current():
$firstThing = $result->current();
$result->next();
$result->next();
$thirdThing = $result->current();
It's just an example, but it can be useful in some cases.
I am trying to write a simple function to clean a filename string and update the object. When I save a test string it works, but when I try to save the string variable I've created, nothing happens. But when I return the string, the output seems to be correct! What am I missing?
def clean_filename
clean_name = filename
clean_name.gsub! /^.*(\\|\/)/, ''
clean_name.gsub! /[^A-Za-z0-9\.\-]/, '_'
clean_name.gsub!(/\_+/, ' ')
#update_attribute(:filename, "test") #<-- correctly sets filename to test
#update_attribute(:filename, clean_name) #<-- no effect????? WTF
#return clean_name <-- seems to returns the correct string
end
Thank you very much.
Is the update only going through if the object ID has changed? I think it is reasonable to update the slot only when the object itself has changed.
Have you ever tried to use gsub instead of gsub!, so that the object ID changes?