samedi 9 octobre 2021

Storing and retrieving data from session in laravel 5.6

I am using laravel 5.6 and my php is 7.3. I am trying to store data in session. I tried

use Session;
session()->put( 'item_data', [1,2,3]);
dd(Session::get( 'item_data' )); 

it shows value properly but problem is if I tried another request then it's showing null. That's mean it's working instantly storing in session. After that showing null



via Chebli Mohamed

vendredi 8 octobre 2021

Store encrypted texts in the database , query and decrypt it back base on password

I'm trying to store an encrypted text in my database, but I have no idea how to decrypted it back. I've tried

$salt   = 'c0d4#';
$pepper ='nsa-cia-fbi'; // secret text

$pwd_peppered = hash_hmac("sha256", $salt, $pepper);
$pwd_hashed = password_hash($pwd_peppered, PASSWORD_ARGON2ID);

echo($pwd_hashed);

// right password hash 
$pwd_hashed = '$argon2id$v=19$m=65536,t=4,p=1$QnVpT1Rqay5WSmIvRW1HZg$rgx+DWPl5bvjwlr7plnOjnE1Sf8lim01pwb6lHGzEaU';

//wrong password hash : for testing purposes 
$pwd_hashed_wrong = '$argon2id$v=19$m=65536,t=4,p=1$QnVpT1Rqay5WSmIvRW1HZg$rgx+DWPl5bvjwlr7plnOjnE1Sf8lim01pwb6lHGzEaU-wrong-!!';

if (password_verify($pwd_peppered, $pwd_hashed)) {
    echo "Password matches.";

   // I am inside this block of codes, but ... 
   // no idea how to decrypt and get my text back ... 😵



}
else {
    echo "Password incorrect.";
}


via Chebli Mohamed

jeudi 7 octobre 2021

Editing a data table inline without updating data to mongo database

am working on Laravel and my project is broadcasting so I have data coming form mongodb into my html table now I want to edit that table inline and without updating to database I want to send this edited table through mail How can I achieve this please provide solutions as m new to development



via Chebli Mohamed

How do store/query sensitive text in the database with salt password?

I'm on Laravel 5.8, I need to store/query tokens in the table in the database.

Ex. My token is

eyJhbGciOiJS1234zz

To add an extra layer of Cryptography

I would like to store it with a specific password, ex. snow

I can add this in .env like this SALT_PASSWORD=snow

I want to do something like this

encrypt(salt(env('SALT_PASSWORD'), 'eyJhbGciOiJS1234zz'))


so only the people who know the SALT_PASSWORD can decrypt the token.


decrypt(salt(env('SALT_PASSWORD'), 'eyJhbGciOiJS1234zz'))

I'm not sure what I am trying to do is call, or possible in PHP.

Can someone please shed some lights on this ?



via Chebli Mohamed

I found Fatal Error in Stripe Integration

Fatal error: Uncaught (Status 400) (Request req_0uWOhuErSVVYrT) Must provide source or customer. thrown in C:\xampp\htdocs\augermates\stripe\vendor\stripe\stripe-php\lib\Exception\ApiErrorException.php on line 38

<?php 
include('config.php');

$price=500;
$name="augermates";

$token=$_POST['stripeToken'];

$data=\Stripe\Charge::create(array(
  "amount"=> 500,
  "currency"=> "USD",
  "Description"=> "augermates",
  "Source"=>$token,


));

echo "<pre>";
print_r($token);


 ?>


via Chebli Mohamed

Trying to Save Comments but the application redirects me to an empty page

I've made a blog and now I'm trying to implement a comment section. I want it so that when the user tries to post, it's saves the comment and redirects the user to the same page. But when I write a comment and try to post it, the application redirects me to a different page. I'm learning how to make a blog with laravel, so I don't know when to use url and when to use routes. Here's the code that I've written.

@auth
        <div class="card ml-5 col-lg-8">
            <ul class="list-group list-group-horizontal">
                <h5 class="list-group-item active">
                    Comments
                <h5>
                <div class="card-body">
                <form method="post" action="">
                @csrf
                    <textarea name="comment" class="form-control py-5"></textarea>
                    <input type="submit" class="btn btn-primary mt-3">
                </div>
                    
            </ul>
        </div>
        @endauth
        <div class="card ml-5 col-lg-8">
            <h5 class="card-header mb-4">Comments<span class="badge badge-info ml-2"> </span></h5>
            <div class="card-body mt-3">
                @if($blog->comments)
                    @foreach($blog->comments as $comment)
                    <blockquote class="blockquote">
                        <p class="mb-0"></p>
                        <footer class="blockquote-footer">Username</footer>
                    </blockquote>
                    <hr>
                    @endforeach
                @endif
            </div>
        </div>

**BlogController**
function save_comment(Request $request,$slug,$id)
{
    $request->validate([
        'comment'=>'required',
    ]);
    $data = new Comment;
    $data->user_id=$request->user()->id;
    $data->post_id=$id;
    $data->comment=$request->comment;
    $data->save();
    return back();
}

**Routes**
Route::get('/blog/', [App\Http\Controllers\BlogController::class, 'index'])->name('blog');
Route::get('blogs/{slug}','App\Http\Controllers\BlogController@getArticles')->name('article.show');
Route::get('blog.update/{id}','App\Http\Controllers\BlogController@edit');
Route::put('blog.update/{id}','App\Http\Controllers\BlogController@update');
Route::post('save_comment/{slug}/{id}','App\Http\Controllers\BlogController@save_comment')->name('save_comment');
Route::get('/admin/blog', 'App\Http\Controllers\BlogController@getBlog')->name('admin.blog');

If there's someone willing to assist come up with a solution to this problem, please assist me. I think the problem lies where I've written the url lies. When I change the url to route, it gives me an error of route not defined. Route::resource('/blog','App\Http\Controllers\BlogController');



via Chebli Mohamed

Have run laravel docker shift from 5.3 to 5.4 and 5.4 to 5.5 with problems

When running composer update it works until @php artisan package:discover I then got: In ProviderRepository.php line 208: Class 'Barryvdh\Cors\ServiceProvider' not found
Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1

I got Barryvdh\Cors\ServiceProvider class defined in app.php enter image description here

So php artisan does not work at all. So what could be the problem?



via Chebli Mohamed